我有一个问题。我列了一个清单如下:
List<Map<String, String>> ShopsList = new ArrayList<Map<String,String>>();
private void initList() {
// We add the cities
ShopsList.add(createShop("Antwerpen", "Broer Bretel"));
ShopsList.add(createShop("Antwerpen", "Caffènation"));
ShopsList.add(createShop("Antwerpen", "Caffènation - Take Out Nation"));
ShopsList.add(createShop("Antwerpen", "Coffeelabs"));
ShopsList.add(createShop("Antwerpen", "De Dikke Kat"));
ShopsList.add(createShop("Antwerpen", "Mlle Loustache"));
ShopsList.add(createShop("Berchem", "Broer Bretel"));
ShopsList.add(createShop("Berchem", "Caffènation"));
ShopsList.add(createShop("Berchem", "Caffènation - Take Out Nation"));
和
private HashMap<String, String> createShop(String key, String name) {
HashMap<String, String> shop = new HashMap<String, String>();
shop.put(key, name);
return shop;
}
所以现在我使用 SimpleAdapter 在 Listview 中显示这个列表。但我想要的是能够只显示具有特定关键字的列表中的数据。所以我愿意
ListView lv = (ListView) findViewById(R.id.listView);
SimpleAdapter simpleAdpt = new SimpleAdapter(this, ShopsList, android.R.layout.simple_list_item_1,
new String[] {"Antwerpen"}, new int[] {android.R.id.text1});
lv.setAdapter(simpleAdpt);
当我这样做时,他只向我显示带有正确关键字的数据,但将其他条目添加为空。因此,当我要求第二个关键字时,他首先添加了 6 个空白位置,然后才显示正确的条目。
我该怎么做?我想我应该使用 Wanted 关键字添加条目的位置,但是如何以简单的方式检索这些位置?
谢谢!