【问题标题】:how to delete a listview item as code below? [duplicate]如何删除列表视图项,如下代码? [复制]
【发布时间】:2014-09-09 03:12:45
【问题描述】:

我只需要从这个列表中删除一个项目,我已经有了我想要的索引但找不到删除的方法。

ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
SongsManager plm = new SongsManager();

// get all songs from sdcard
this.songsList = plm.getPlayList();

// looping through playlist
for (int i = 0; i < songsList.size(); i++) {
    // creating new HashMap
    HashMap<String, String> song = songsList.get(i);

    // adding HashList to ArrayList
    songsListData.add(song);
}

// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(
    this,
    songsListData,
    R.layout.playlist_item,
    new String[] { "songTitle" },
    new int[] { R.id.songTitle2 });

setListAdapter(adapter);

【问题讨论】:

    标签: java android listview arraylist


    【解决方案1】:

    如果你已经有了索引,试试这些 songsListData.remove(index); adapter.notifyDataSetChanged(); 也许在 onItemClick

    【讨论】:

    • 我的适配器有“notifyDataSetChanged()”选项。 ://
    • songsListData.remove(aux); ((BaseAdapter) 适配器).notifyDataSetChanged();正在工作,现在只缺移动sdcard也
    • String selectedFilePath = songList2.get(aux).get("songPath");文件 file = new File(selectedFilePath);文件.删除();现在是的!!!:D
    【解决方案2】:

    首先从您的歌曲列表数据集合中删除项目并重新加载列表视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2020-12-05
      • 1970-01-01
      相关资源
      最近更新 更多