Я хочу добавить кнопку «Добавить» для каждого дочернего элемента моего ExpandableListView.Это мой код адаптера.Когда у меня есть несколько растяжимых списков и я нажимаю одну кнопку, значение текстового просмотра изменяется в каждом дочернем элементе, а не только в дочернем, который я щелкнул.
На самом деле btclicked просто изменяет текстовое представление в «1», но этоэто просто тест.Я изменю это, когда я улажу это.
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;
}
}