2015-11-04 118 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作家有很多關於列表視圖的東西,比如自定義適配器等。希望它有幫助。

乾杯