当我检查一个项目在烤面包片中显示但我希望当我检查多个项目时在面包片中显示它的名字

时间:2019-10-31 21:13:19

标签: android android-listview

当我在烤面包中检查一项时,但我希望在我检查多个项目时要在烤面包中显示其名称。

String[] items;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Resources r = getResources();
        items = r.getStringArray(R.array.items);

        ArrayAdapter<String> aa = new ArrayAdapter<String>(
                this,
                android.R.layout.simple_list_item_multiple_choice,
                items);

        setListAdapter(aa);

        ListView lv = getListView();
        lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Toast.makeText(v.getContext(), items[position].toString(),Toast.LENGTH_SHORT).show();
    }
}

term

1 个答案:

答案 0 :(得分:1)

您可以尝试

// make temporary array to store your List view value   
 private ArrayList<String> tempArray = new ArrayList();

        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {

            tempArray.add(items[position].toString());
            String allItems = "";
            for (int i = 0; i < tempArray.size(); i++) {
                allItems = allItems + "\n" + items[position].toString();
            }
            Toast.makeText(v.getContext(), ""+allItems, Toast.LENGTH_SHORT).show();
        }