androidlistviewsimpleadapter

android + custom list view


i am trying to make a custom list view and was following this post http://saigeethamn.blogspot.in/2010/04/custom-listview-android-developer.html

the list view accepted the custom row.. but only displays the first item... none of the rest.. so what is the mistake? thanks in advance..

 public class ActionBarSearchView extends ListActivity {
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.forummainpage);

        SimpleAdapter adapter = new SimpleAdapter(
                ActionBarSearchView.this,
                list,
                R.layout.customlistrowview,
                new String[] {"Title","Tags","Date","Author"},
                new int[]{R.id.Title,R.id.Tags,R.id.Date,R.id.Author});
        populateList();
        setListAdapter(adapter);
 }
  static final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
  private void populateList()
    {
        HashMap<String,String> temp = new HashMap<String,String>();
        temp.put("Title","android an Immersive Journey");
        temp.put("Tags", "android");
        temp.put("Date", "2 years");
        temp.put("Author", "xyz");
        list.add(temp);

        HashMap<String,String> temp1 = new HashMap<String,String>();
        temp.put("Title","android an Immersive Journey");
        temp.put("Tags", "android");
        temp.put("Date", "2 years");
        temp.put("Author", "xyz");
        list.add(temp1);

        HashMap<String,String> temp2 = new HashMap<String,String>();
        temp.put("Title","android an Immersive Journey");
        temp.put("Tags", "android");
        temp.put("Date", "2 years");
        temp.put("Author", "xyz");
        list.add(temp2);

        HashMap<String,String> temp3 = new HashMap<String,String>();
        temp.put("Title","android an Immersive Journey");
        temp.put("Tags", "android");
        temp.put("Date", "2 years");
        temp.put("Author", "xyz");
        list.add(temp3);

        HashMap<String,String> temp4 = new HashMap<String,String>();
        temp.put("Title","android an Immersive Journey");
        temp.put("Tags", "android");
        temp.put("Date", "2 years");
        temp.put("Author", "xyz");
        list.add(temp4);
    }

Solution

  • You always add data into your HashMap temp. you need to add data into your different HashMap like

     HashMap<String,String> temp1 = new HashMap<String,String>();
        temp1.put("Title","android an Immersive Journey");
        temp1.put("Tags", "android");
        temp1.put("Date", "2 years");
        temp1.put("Author", "xyz");
        list.add(temp1);
    

    then

    HashMap<String,String> temp1 = new HashMap<String,String>();
        temp2.put("Title","android an Immersive Journey");
        temp2.put("Tags", "android");
        temp2.put("Date", "2 years");
        temp2.put("Author", "xyz");
        list.add(temp2);
    

    and so on.