【问题标题】:Edit an item in a ListView using Simple Adapter使用简单适配器编辑 ListView 中的项目
【发布时间】:2015-11-04 13:46:42
【问题描述】:

我有一个使用 SimpleAdapter 填充的 ListView:

List<Map<String, String>> listItems = new ArrayList<>();
listItems.add(createItemMap(R.string.rename_mobtag, R.string.rename_mobtag_help));
listItems.add(createItemMap(R.string.change_icon, R.string.change_icon_help));
listItems.add(createItemMap(R.string.become_invisible, R.string.become_invisible_help));

ListView mobtagSettings = (ListView) findViewById(R.id.mobtag_settings);
    final String[] fromMapKey = new String[]{TITLE_KEY, HELP_KEY};
    final int[] toLayoutId = new int[]{android.R.id.text1, android.R.id.text2};
    SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems, android.R.layout.simple_list_item_2, fromMapKey, toLayoutId);
    mobtagSettings.setAdapter(simpleAdapter);

我需要更新特定项目的 TextViews 以响应外部事件(因此我不能为此使用 Click 侦听器)。如何获取 TextView 以便更改其文本?

【问题讨论】:

    标签: android listview simpleadapter


    【解决方案1】:

    只需创建一个包含更改的新列表并在适配器中更新该列表并调用 notifyDatasetChanged 方法

    【讨论】:

      【解决方案2】:

      对于特定的 TextView 项目,您知道该项目在列表中的位置/索引吗?您可能希望创建自己的自定义适配器,该适配器将在适配器列表中包含对该特定项目的更新功能,以便您可以更新该项目的 Textview。

      你可以参考http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown_custom,作者有很多关于列表视图的东西,比如自定义适配器等。希望对你有帮助。

      干杯

      【讨论】:

        猜你喜欢
        • 2013-07-16
        • 2013-02-27
        • 1970-01-01
        • 2020-07-20
        • 1970-01-01
        • 2013-09-08
        • 1970-01-01
        • 1970-01-01
        • 2019-02-22
        相关资源
        最近更新 更多