Re: [問題] content view的問題

看板AndroidDev作者 (〆)時間13年前 (2011/08/03 15:24), 編輯推噓3(301)
留言4則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《neko0624 (Neko)》之銘言: : 請問 : 在Activity中有setContentView跟addContentView兩種方法 : 那有沒有能移除ContentView的方法或是技巧呢 : 我用addContentView加了好幾層的View上去 : 現在要移除掉幾個已經加上去的View 推文太麻煩 直接寫一隻程式給你參考 package com.givemepass.TestContentView; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public class TestContentView extends Activity { private LinearLayout linearlLayout; private Button button; private TextView [] textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); //linearlLayout = (LinearLayout)findViewById(R.id.linearLayout01); linearlLayout = new LinearLayout(this); linearlLayout.setOrientation(LinearLayout.VERTICAL); setContentView(linearlLayout); button = new Button(this); textView = new TextView[10]; linearlLayout.addView(button); for(int i=0;i<10;i++){ textView[i] = new TextView(this); textView[i].setText("TextView"+i); linearlLayout.addView(textView[i]); } button.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { if(linearlLayout.getChildCount()!=1){ linearlLayout.removeViewAt( linearlLayout.getChildCount()-1); } } }); } } 我試過了 可以動 直接copy paste就可以了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.221.115.4

08/03 15:42, , 1F
感謝 我來研究一下
08/03 15:42, 1F

08/03 15:59, , 2F
讚 今天釐清不少觀念 光是Android的View就可以研究半年了
08/03 15:59, 2F

08/03 16:45, , 3F
看到此文,受益良多!!
08/03 16:45, 3F

08/05 13:32, , 4F
問題解決了 感謝大大
08/05 13:32, 4F
文章代碼(AID): #1EEFUWSf (AndroidDev)
討論串 (同標題文章)
文章代碼(AID): #1EEFUWSf (AndroidDev)