我有一个从几个按钮的 onClick 填充的 ArrayList。我试图弄清楚如何让我的 ArrayList 将类似的项目组合成一个项目。用户按下按钮一次,列表中将填充“1 不管”。如果他们再次按下相同的按钮,它将在列表中再次显示“1whatever”然后“1whatever”。如果按钮被按下两次,我如何让我的列表显示“2whatever”?
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
//Regular List
adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,listItems);
setListAdapter(adapter);
//List From Another Activity
ArrayList<String> ai= new ArrayList<String>();
ai = getIntent().getExtras().getStringArrayList("list");
if (ai != null) {
listItems.add(ai+"");
adapter.notifyDataSetChanged();
}
//When the User pushes this button
//StackOverFlow help, Ignore this part if it's useless...wasnt sure
lay1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
listItems.add("1 "+stringm1a+" - "+intm1aa );
adapter.notifyDataSetChanged();
overallTotalproduct = intm1aa + overallTotalproduct;
textViewtotalproduct.setText(String.valueOf(overallTotalproduct));
}
});