listview

How to add divider items to ListView

SDK Version: 
M3

Today I'm going to show an easy way to add divider items to your ListView.
First off, you need your own ListView Adapter which extends SimpleAdapter. If you don't know how to create a new class for your own SimpleAdapter, please go and visit: http://developer.android.com/resources/samples/ApiDemos/src/com/example/...

Ok, so here's how it looks like:

  1. public class SpecialAdapter extends SimpleAdapter {
  2.         private LayoutInflater mInflater;
  3.         private List<HashMap<String, String>> items;
  4.  
  5.         public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
  6.                 super(context, items, resource, from, to);
  7.                 // Cache the LayoutInflate to avoid asking for a new one each time.
  8.         this.items = items;
  9.         }
  10.  
  11.          @Override
  12.      public boolean areAllItemsEnabled() {
  13.          return false;
  14.      }
  15.  
  16.      @Override
  17.      public boolean isEnabled(int position) {
  18.          boolean enabled = false;

How to update custom listview images simply

SDK Version: 
M3
So in this tutorial I'm going to show you how to refresh imageviews' contents periodically (let say by Handlers if you download the picture from web).
I had painful 2 days figuring out what's a good solution here, I tried to give IDs to imageviews and that sort of sick things, but believe me, it wasn't worth it. The solution is so simply that I hardly can believe.
What we're lookign for here is instead of create new Adapters and HashMaps (which contains ListView data), we just update it's values, and Android will do the trick for us.
The most important thing is DO NOT 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() { }.

Let me show you how it works:

Syndicate content