listView获得CheckBox 的位置
当一个lsitView中每个ietm有多个控件的时候想获得其中的位置,其实主要是item的位置
@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?
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? });?
? ? }?
}?
2.
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.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {?
? ? ? ? ? ? ? ? ? ? public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {?
? ? ? ? ? ? ? ? ? ? ? ? ViewGroup v = (ViewGroup)buttonView.getParent().getParent();?
? ? ? ? ? ? ? ? ? ? ? ? int i = v.indexOfChild((View)buttonView.getParent());?
? ? ? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ? });?
? ? ? ? }?
? ? }?
?