你可以嘗試通過它的位置,而當onCheckedChangeListener被炒魷魚,得到複選框的標籤來獲取其位置上的複選框設置標籤..
這裏是一個示例代碼,但我沒有試過它
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// grab view
View v = convertView;
// set view layout
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.layout_inbox_item, null);
CheckBox box = (CheckBox)v.findViewById(R.id.inbox_itemcheck);
if (box != null) {
box.setTag(position); //<-- sets the tag by its position
box.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int position = (Integer)buttonView.getTag(); //<-- get the position
}
});
}
}
有人發佈此解決方案,然後刪除解決方案,一旦我提出了我的問題。我的問題是我的列表可以被用戶改變(例如:刪除一行)。這會混淆刪除行下面的行的所有索引。 – Andrew 2010-08-13 13:57:49
我想不出比您提供的更簡單的解決方案。如果我是你,我會去那個。 – capecrawler 2010-08-26 08:12:05