[問題] 自定的 Adapter 在 getView()時為空
在自定義的 adapter 的
getView(int position, View convertView, ViewGroup parent) 中
對 convertView 做了 null 的判斷
if(convertView != null){
myItem = (ItemView) convertView.getTag(); //這裡會為空
...
} else {
convertView = mInflater.inflate(mRes, null);
...
}
而我現在的狀況是 convertView 不為空,所以會進到 true 的區段裡
但 getTag() 卻為空
請問有人遇過這種情形嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.154.220
推
08/08 19:19, , 1F
08/08 19:19, 1F
推
08/08 19:57, , 2F
08/08 19:57, 2F
*[1;31m→ *[33modin2008*[m*[33m:我有 setTag() 哦
在 else 那段的最後有加上 convertView.setTag(myItem);
不過我找到一個癥結,在 else 的區塊裡一開始的第三行就有問題
convertView = mInflater.inflate(mRes, null);
mItem = new ItemView();
mItem.myName = (TextView)convertView.findViewById(mViewId[0]);
這時候的 mItem.myName 是 null
也就是說他沒有找到該 View ID 的內容
而我的 mViewId[0] 的來源是這樣
new int[]{R.id.txtMyName}
他是一個 Layout 中的 TextView,而且確定是有值的
只是不知道為何,到這裡就變空的了,再麻煩解惑,感謝^_^
補充一下,我有直接將 mViewId[0]
改成 R.id.txtMyName 仍然是 null orz
※ 編輯: odin2008 來自: 60.251.154.220 (08/09 09:03)
※ 編輯: odin2008 來自: 60.251.154.220 (08/09 09:06)
※ 編輯: odin2008 來自: 60.251.154.220 (08/09 09:40)
→
08/09 12:55, , 3F
08/09 12:55, 3F
→
08/09 15:47, , 4F
08/09 15:47, 4F