First you have to remember Don't at any circumstances create a new adapter (or a new data source that holds the Adapter's data).
There's an exception of course, you obviously have to create a new Adapter in OnCreate() { }.
Create a new ArrayList of HashMaps that holds the data
we can fill it up by calling:
and then, we add it to the List:
We can do this over n over, as many times as we want.
Create a new Adapter in your OnCreate() {}
What we're doing here is that we create a new SimpleAdapter, and tell it to use hashMapForListView as data source, and also tell the listView to use adapterForList as Adapter.
R.layout.detailedview is my own Layout file, that includes 3 textviews called "R.id.EntityName, R.id.Category, R.id.Price, " and an ImageView called "R.id.ThumbImage".
As you can see, we tell the Adapter to use these UI elements.
The refreshing
Since we have data in the List of HashMaps, we can overwrite the values, simply by calling
Don't forget to create a new instance of entitiesHashMap, and set it's values just as we did in above to get the result you'd expect. and you have to watch more tutorials goto:http://www.helloandroid.com/tutorials/how-update-custom-listview-images-simply
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/
http://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/
There's an exception of course, you obviously have to create a new Adapter in OnCreate() { }.
Create a new ArrayList of HashMaps that holds the data
hashMapListForListView = new ArrayList<HashMap<String,String>>();
we can fill it up by calling:
entitiesHashMap.put("name", "Ball");entitiesHashMap.put("category", "Sport");entitiesHashMap.put("price", "2.99");entitiesHashMap.put("imageUri", ball.Uri);
and then, we add it to the List:
- hashMapListForListView.add(entitiesHashMap);
We can do this over n over, as many times as we want.
Create a new Adapter in your OnCreate() {}
adapterForList = new SimpleAdapter(Main.this,hashMapListForListView, R.layout.detailedview,new String[] {"name", "category", "price", "imageUri"},new int[] { R.id.EntityName, R.id.Category, R.id.Price, R.id.ThumbImage });listView.setAdapter(adapterForList);
What we're doing here is that we create a new SimpleAdapter, and tell it to use hashMapForListView as data source, and also tell the listView to use adapterForList as Adapter.
R.layout.detailedview is my own Layout file, that includes 3 textviews called "R.id.EntityName, R.id.Category, R.id.Price, " and an ImageView called "R.id.ThumbImage".
As you can see, we tell the Adapter to use these UI elements.
The refreshing
Since we have data in the List of HashMaps, we can overwrite the values, simply by calling
hashMapListForListView.set(index, entitiesHashMap);
Don't forget to create a new instance of entitiesHashMap, and set it's values just as we did in above to get the result you'd expect. and you have to watch more tutorials goto:http://www.helloandroid.com/tutorials/how-update-custom-listview-images-simply
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/
http://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/
0 comments
Thanks for your comment