I'm new to android programming and I would like some help. I have the followin开发者_StackOverflowg code:
Object[] list_cities = parsedData.getCityname().toArray();
Object[] list_countries = parsedData.getCountryname().toArray();
// Display the available locations
list_search.setAdapter(new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_2, android.R.id.text1, list_cities));
list_search.setAdapter(new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_2, android.R.id.text2, list_countries));
I would like to display double rows for each entry in the list (city and country) but I have no luck. With the above code I only see the countries but not the cities. Is there any way to add both the adapters to the list_search so I can see all the data?
Thank you all for your answers!!
- Create a custom container object, maybe CountryCityLocation, with a couple strings for country and city name.
- Create an array of these containers and fill it with your information.
- Create a custom ArrayAdapter, maybe CountryCityAdapter, apply the array to the custom adapter, and feed it to getListView.setAdapter.
- Override the ArrayAdapter's getView method to apply your name strings to TextViews in your custom list row view.
EDIT - removed dead tutorial link
You can bind only one adapter to ListView. If you want to combine adapters you need to implement custom adapter. For example you can inherit SimpleAdapter, provide two simple adapters in constructor and combine data in in getItem method.
精彩评论