您可以尝试通过其位置在复选框上设置标签,当 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
}
});
}
}