【问题标题】:Remove Items from list?从列表中删除项目?
【发布时间】:2016-05-08 14:27:00
【问题描述】:

我有一个带有适配器的列表视图和一个数组列表:

   contactArrayList= new ArrayList<String>();
        listview = (ListView) findViewById(R.id.listView);

        arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, contactArrayList);
        listview.setAdapter(arrayAdapter);

我的listview总是包含我的arraylist的内容,因为修改arraylist后,我总是调用arrayAdapter.notifyDataSetChanged();。现在,我怎样才能让用户从 ListView 中删除一个值,并从我的数组中删除它?我知道如何让用户从列表视图中删除一个项目,但现在我想在我的 ArrayList 中删除与该项目对应的字符串。我该怎么做?

【问题讨论】:

  • 只需从数组列表中删除 rhe 项。
  • 显示你现在要删除的代码
  • @JawadLeWywadi 但是我怎么知道他们要删除哪个项目
  • 这取决于你想如何实现它。寻找 onitemclick 或 onlongitemclick...

标签: java android listview arraylist


【解决方案1】:

如果我理解正确,我只需要从您的 ArrayList 中删除该项目。

contactArrayList.remove(positionToRemove);

【讨论】:

  • 我怎么知道他们正在删除哪些
  • 他们究竟是如何从列表中删除项目的?是否有一些要删除的 swype、OnLongClick 或 onContextItemSelect?
猜你喜欢
  • 1970-01-01
  • 2022-12-20
  • 2011-03-18
  • 2020-12-07
  • 2010-11-29
  • 2016-08-17
  • 2019-09-30
  • 1970-01-01
相关资源
最近更新 更多