i want to add an "Add" button to every child of my ExpandableListView. This is my adapter code. When i have more expandableLists and I press one button, the value of the textview change in every child, instead of just the child that i clicked.
Actually the btclicked just change the textview in "1", but this is just a test. I will change it when I have settled this.
public class CustomExpandableListAdapter extends BaseExpandableListAdapter{
private Context context;
private List<String> expandableListTitle;
private HashMap<String, List<Pietanze>> expandableListDetail;
private int idbhub;
private Context classe;
private ArrayList<Integer> count = new ArrayList<>(100);
public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,HashMap<String, List<Pietanze>> expandableListDetail,int idbhub, Context classe)
{
this.context = context;
this.expandableListTitle = expandableListTitle;
this.expandableListDetail = expandableListDetail;
this.idbhub=idbhub;
this.classe=classe;
}
@Override
public int getGroupCount()
{
return this.expandableListTitle.size();
}
@Override
public int getChildrenCount(int listPosition)
{
return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).size();
}
@Override
public Object getGroup(int listPosition)
{
return this.expandableListTitle.get(listPosition);
}
@Override
public Object getChild(int listPosition, int expandedListPosition)
{
return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).get(expandedListPosition).getNome()+" "+this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).get(expandedListPosition).getPrezzo().toString()+" €";
}
@Override
public long getGroupId(int listPosition)
{
return listPosition;
}
@Override
public long getChildId(int listPosition, int expandedListPosition)
{
return expandedListPosition;
}
@Override
public boolean hasStableIds()
{
return false;
}
@Override
public View getGroupView(int listPosition, boolean isExpanded,View convertView, ViewGroup parent)
{
String listTitle = (String) getGroup(listPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_group, null);
}
TextView listTitleTextView = (TextView) convertView
.findViewById(R.id.listTitle);
listTitleTextView.setTypeface(null, Typeface.BOLD);
listTitleTextView.setText(listTitle);
return convertView;
}
@Override
public View getChildView(final int listPosition, final int expandedListPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
final String expandedListText = (String) getChild(listPosition, expandedListPosition);
if (convertView == null)
{
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_item, null);
}
TextView expandedListTextView = (TextView) convertView.findViewById(R.id.expandedListItem);
expandedListTextView.setText(expandedListText);
expandedListTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
AlertDialog.Builder alertingredienti = new AlertDialog.Builder(classe);
alertingredienti.setMessage(expandableListDetail.get(expandableListTitle.get(listPosition)).get(expandedListPosition).getIngredienti()).setTitle("LISTA INGREDIENTI").create();
alertingredienti.show();
}
});
Button btadd = (Button) convertView.findViewById(R.id.add);
Button btsub = (Button) convertView.findViewById(R.id.sub);
final TextView contatore = (TextView) convertView.findViewById(R.id.contatore);
if(idbhub==1)
{
btadd.setText("ADD");
btsub.setText("SUB");
btadd.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
contatore.setText("1");
}
});
btsub.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
}
});
}
else
{
btadd.setVisibility(View.GONE);
btsub.setVisibility(View.GONE);
contatore.setVisibility(View.GONE);
}
return convertView;
}
@Override
public boolean isChildSelectable(int listPosition, int expandedListPosition)
{
return true;
}
}