[問題] setId() 和 findViewById() 的使用
請問一下
我的寫法是在 .java 檔裡面 用 addView 一個一個元件放進去
而非使用一般 /res/layout/XXX.xml的寫法
現在我想幫 TextView 加上ID 以便在其他的地方修改textview的內容
寫法是
TextView mText1 = new TextView(mProject.this);
mText1.setId(1010101);
mText1.setText("123456");
然後在別的地方寫
TextView mText1 = (TextView)findViewById(1010101);
mText1.setText("asdqwe");
然後就出現 nullpointerexception 的錯誤訊息 然後強制關閉
之後有測試在別的地方寫
TextView mText1 = new TextView(mProject.this);
mText1.findViewById(1010101);
mText1.setText("asdqwe");
這樣是不會出錯了
但也沒什麼反應...
請問版上的神人
要怎麼解決這個問題?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.246.208
推
06/02 19:28, , 1F
06/02 19:28, 1F
→
06/02 19:29, , 2F
06/02 19:29, 2F
我連接在下面放 findViewById() 都會出錯...QQ
推
06/02 21:01, , 3F
06/02 21:01, 3F
有很多耶 宣告在外面會宣告不完
※ 編輯: ashlin1112 來自: 220.141.80.88 (06/04 13:31)
→
06/04 21:47, , 4F
06/04 21:47, 4F
→
06/04 21:48, , 5F
06/04 21:48, 5F
就是我現在有一個listView
裡面有很多選項
在擊點選項的時候想對listView裡面的 TextView做修改
謝謝囉
※ 編輯: ashlin1112 來自: 114.39.169.165 (06/05 00:34)
推
06/05 11:28, , 6F
06/05 11:28, 6F
推
06/05 12:32, , 7F
06/05 12:32, 7F