Li Che
Li Che

Reputation: 737

Can not display a ListView in Tab of TabHost

I created the following application. I want to display a ListView in Tab of TabHost. After I run the application, I did not find any ListItem on Tab. I rewrite adapter and implement getView, and then setAdapter.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myTabhost=this.getTabHost();
    LayoutInflater.from(this).inflate(R.layout.activity_main,myTabhost.getTabContentView(),true);
    myTabhost.addTab(myTabhost.newTabSpec("tab1").setIndicator("tab1",getResources().getDrawable(R.drawable.calendar)).setContent(R.id.tab1));
    myTabhost.addTab(myTabhost.newTabSpec("tab2").setIndicator("tab2",getResources().getDrawable(R.drawable.ic_launcher)).setContent(R.id.tab2));
    myTabhost.addTab(myTabhost.newTabSpec("tab3").setIndicator("tab3").setContent(R.id.tab3));
    listView1=(ListView) findViewById(R.id.listView1);

    data=new ArrayList<Map<String,Object>>();
    Map<String,Object> item;
    item=new HashMap<String,Object>();
    item.put("date", "2012-12-25");
    item.put("item","Christmas");
    data.add(item);

    item.put("date", "2013-1-1");
    item.put("item", "new year");
    data.add(item);

    SimpleAdapter adapter=new SimpleAdapter(this, data, android.R.layout.simple_expandable_list_item_2, new String[]{"date","item"}, new int[]{R.id.textView1,R.id.textView2});
    listView1.setAdapter(adapter);
}

could you help me and find where is the problem?

Upvotes: 0

Views: 193

Answers (2)

Rino
Rino

Reputation: 1215

The TabActivity class was deprecated in API level 13. New applications should use Fragments instead of this class.

Upvotes: 0

Digvesh Patel
Digvesh Patel

Reputation: 6533

every time u have to use new hash map object to store data in arraylist with help of hash map

 Map<String,Object> item = new HashMap<String,Object>();
      item.put("date", "2012-12-25");
      item.put("item","Christmas");
      data.add(item);

 Map<String,Object> item1 = new HashMap<String,Object>();
      item1.put("date", "2013-1-1");
      item1.put("item", "new year");
      data.add(item1);

Upvotes: 1

Related Questions