【问题标题】:Add modifications to each custom listview item为每个自定义列表视图项添加修改
【发布时间】:2016-10-07 00:15:23
【问题描述】:

所以现在我有一个自定义列表视图适配器,当用户选择一个项目时,它会添加另一行。问题是,行中的每个项目都应该有一个修改按钮,他们可以在其中选择添加任何修改(可以选择多个修改)

This is a food ordering app that when the item is selected, there should be another button in the list labeled "Modify", where a pop-up comes up and allows the user to choose what modification it wants by using checkbox. (“少盐”、“多酱”等)。每道菜的每个修改列表都是相同的。当用户退出弹出窗口并单击同一个修改按钮时,选中的复选框应保留在那里。

我最初创建了一个弹出类,其中选择按钮时,有一个意图跳到该弹出活动,但是我找不到自定义适配器和弹出活动之间的关系。我还尝试使用 AlertDialog 替换 Popup 窗口,但找不到保存所有选中项目并显示之前选择的项目的方法。

这是我的代码

    modifyBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

           AlertDialog.Builder builder = new AlertDialog.Builder(context);
           builder.setTitle("Modification");

            final CharSequence[] modify_items = orderClass.getModifyList()
                    .toArray(new CharSequence[orderClass.getModifyList().size()]);
            builder.setMultiChoiceItems(modify_items, null, new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
                    if(isChecked){
                        selectedList.add(indexSelected);
                        selectedItems.set(position, selectedList);
                    }
                    else if(selectedList.contains(indexSelected)){
                        selectedList.remove(Integer.valueOf(indexSelected));
                        selectedItems.set(position, selectedList);
                    }
                }
            })
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    })
                    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });
            AlertDialog dialog = builder.create();
            dialog.show();
            Log.d("dialog", "Showing dialog");


        }
    });


    return view;
}

【问题讨论】:

    标签: android listview


    【解决方案1】:

    你需要把数据放在一个持有者结构中(它有点像一个持有变量的类) 然后您可以按索引显示数据,并且显示的列表视图索引和数据索引之间存在关系,因此当单击列表视图单元格时,您会获得该位置,然后在结构中找到它并将其发布到另一个活动或其他任何内容修改它记住你必须声明一个标志来启动活动,否则应用程序将崩溃我认为它称为 activtyoutofbound 索引或类似的东西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多