我试图制作ExpandableListView,其中每个孩子都有一个复选框,每个组都有TextView,以后我想输出所选孩子数量的文本(例如3/26)。现在我只想尝试获取被点击子项的groupPosition和childPosition或子视图中的复选框。但是当我点击它们时 - 没有任何反应,我没有得到任何记录,也没有得到Toast消息。
这是我的适配器代码:
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final ChildHolder child_holder;
if(convertView == null)
{
convertView = LayoutInflater.from(context).inflate(R.layout.row_base_item_selected, null);
child_holder = new ChildHolder();
child_holder.tv_bi_name = (TextView) convertView.findViewById(R.id.tv_base_item_name_selected);
child_holder.chb_selected = (CheckBox) convertView.findViewById(R.id.chb_selected);
convertView.setTag(child_holder);
} else {
child_holder = (ChildHolder) convertView.getTag();
}
final Group group = arr_groups.get(groupPosition);
final Base_Item base_item = group.getGroup_items().get(childPosition);
if(base_item!=null)
{
child_holder.tv_bi_name.setText(base_item.getItem_name());
if(base_item.isBase_item_selected())
{
child_holder.chb_selected.setSelected(true);
}
}
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final Group group = arr_groups.get(groupPosition);
convertView = inflater.inflate(R.layout.row_group, parent, false);
((TextView)convertView.findViewById(R.id.tv_category_name)).setText(group.getGroup_name());
ImageView img_add = (ImageView) convertView.findViewById(R.id.img_add_category);
img_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mListener.onImageClicked(group.getGroup_id());
}
});
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
class GroupHolder{
TextView tv_group_name;
TextView tv_items_counter;
}
class ChildHolder{
TextView tv_bi_name;
CheckBox chb_selected;
}
这是活动代码:
Task_DB_Manager manager;
ArrayList<Group> arr_all_groups;
Add_Edit_Trip_Expandable_ListView_Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_edit_trip_relative);
lv_trip_list = (ExpandableListView) findViewById(R.id.elv_trip_list);
manager = new Task_DB_Manager(this);
populate_list();
}
private void populate_list()
{
arr_all_groups = manager.get_all_groups();
adapter = new Add_Edit_Trip_Expandable_ListView_Adapter(this, arr_all_groups);
lv_trip_list.setAdapter(adapter);
lv_trip_list.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.e("Group position :: "+groupPosition, " && Child position :: "+childPosition);
Toast.makeText(Activity_Add_Edit_Trip.this, "Group position :: "+groupPosition+"\nChild position :: "+childPosition, Toast.LENGTH_SHORT).show();
return false;
}
});
set_image_click_listener();
}
为什么我没有得到childPosition和groupPosition?