【问题标题】:android studio delete from listivewandroid studio 从列表视图中删除
【发布时间】:2020-12-10 16:11:28
【问题描述】:

我正在尝试使用 CustomAdapter 使用下面的编码从 Listview 中删除和刷新

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    SubjectData subjectData = arrayList.get(position);


    if (convertView == null) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        convertView = layoutInflater.inflate(R.layout.notifications_list, null);

        listView = convertView.findViewById(R.id.notificationlist);


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

                String item = subjectData.notice_id.toString();
                arrayList.remove(item);
                listView.refreshDrawableState();

            }
        });

【问题讨论】:

  • 嗨,Adam,您能否提供有关您在何处以及如何创建 adaper 的信息?

标签: android


【解决方案1】:

您可以使用adapter.notifyDataChanged()

【讨论】:

  • 我确实尝试添加 adapter.notifyDataChanged() 并且应用程序崩溃
【解决方案2】:

删除您的项目后使用arrayAdapter.notifyDataSetChanged();。

You can follow this answser

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    相关资源
    最近更新 更多