2015-11-04 58 views
0

使用SimpleAdapter我已经一个ListView填充在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响应于外部事件(因此我不能使用点击监听器)。我怎么能得到的TextViews,所以我可以改变他们的文本?

回答

1

只是使含有所述变化的一个新的列表,并在适配器更新列表和电话notifyDatasetChanged方法

1

对于特定TextView的项目,你知不知道在你的列表中的位置/该项目的指标?您可能需要创建自己的自定义适配器,该适配器将包含适配器列表中特定项目的更新功能,以便您可以更新该项目的Textview。

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

干杯