首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

listView取得CheckBox 的位置

2012-09-19 
listView获得CheckBox 的位置当一个lsitView中每个ietm有多个控件的时候想获得其中的位置,其实主要是item

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());?
? ? ? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ? });?
? ? ? ? }?
? ? }?

?

热点排行