【问题标题】:To remove the single item in listview in android?在android的listview中删除单个项目?
【发布时间】:2023-03-04 08:54:01
【问题描述】:

单击长按时,我必须从 android 的列表视图中删除单个项目。请给我合适的代码来删除列表视图中的项目? 这是我的代码

        this.getListView().setLongClickable(true);
        this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto - generated method stub

            }
}

【问题讨论】:

标签: java android listview


【解决方案1】:

在 ArrayAdapter 中使用 remove() 方法。

yourarrayAdapter.remove(yourarrayAdapter.getItem([POSITION]));

yourarrayList.remove([POSITION]);
yourarrayAdapter.notifyDataSetChanged();

【讨论】:

    【解决方案2】:

    在你的点击回调中试试这个,从它的父视图中移除视图:

    ((ViewManager) parent).removeView(view);
    

    【讨论】:

      猜你喜欢
      • 2011-02-03
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      相关资源
      最近更新 更多