Search code examples
androidlistviewsimpleadapter

Edit an item in a ListView using Simple Adapter


I have a ListView populated using a SimpleAdapter:

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);

I need to update the TextViews for a particular item in response to an external event (hence I cannot use the Click listener for that). How can I do get the TextViews so I can change their texts?


Solution

  • just make a new list containing the change and update that list in the adapter and call notifyDatasetChanged method