android - Simple Adapter to show part of List (made with Hashmap) by keyword -


i have of problem. i've made list following:

list<map<string, string>> shopslist = new arraylist<map<string,string>>();        private void initlist() {         // add 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")); 

and

private hashmap<string, string> createshop(string key, string name) {         hashmap<string, string> shop = new hashmap<string, string>();         shop.put(key, name);         return shop;        } 

so use simpleadapter diplay list in listview. want able show data list specific keyword. do

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

when this, shows me data right keyword, adds other entry's empty. when ask second keyword, first adds 6 empty places before displaying right entry's.

how should this? think should add locations of entry's wanted keyword, how retrieve these locations in easy way?

thanks!

edit:

as pointed out, mistaken simpleadapter arrayadapter. apologies , if want change implementation arrayadapter (which simpler imho), code below.

original:

when filling android.r.id.text1 values, arrayadapter calls .tostring() in each element list.

there're several ways accomplish want.

  • one of them make list<string> , make strings want seen on screen.

  • a valid more "o.o." approach create own class.

for example:

public class shop{    private string city;    private string name;     public shop(string city, string name){        this.city = city;        this.name = name;    }     @override    public string tostring() {        return city + " - " + name    } } 

and on adapter you'll use list<shop> instead of map. , overriding tostring() method can manipulate text wish.

  • just mention, way of doing extending listadapter class

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -