Reputation: 6083
I'm trying to make ExpandableListView where every child has a checkbox and every group has TextView where later I want to output text with amount of selected children out of total (i.e. 3/26, for example). For now I'm just trying to get the groupPosition and childPosition of the clicked child or the checkbox in the child view. But when I click on them - nothing happens, I don't get no log record, not Toast message.
Here's my code from Adapter:
@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;
}
This is the Activity code:
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();
}
Why don't I get the childPosition and groupPosition?
Upvotes: 0
Views: 687