2013年9月24日星期二

In a TabHost Tab page you want to display on a ListView, why not come out ?

The code below, but after running on the Tab does not show a ListItem, what 's the problem ?

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 item;
item = new HashMap ();
item.put ("date", "2012-12-21");
item.put ("item", " Armageddon " ) ;
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);

}
------ Solution --------------------------- -----------------
I usually rewrite the adapter, and then implement getView, then setAdapter
------ Solution ------- -------------------------------------
should be the adapter problem , put a floor Yes, a custom adapter will be better
------ Solution ------------------------------- -------------
which version you use ?

Every time you must use the new hash map object to store the data in arraylist

Map item = new HashMap();

        item.put("date", "2012-12-25");

        item.put("item","Christmas");

        data.add(item);

Map item1 = new HashMap();

        item1.put("date", "2013-1-1");

        item1.put("item", "new year");

data.add(item);








------ For reference only ---------------------------------- -----
ask the landlord how to solve this problem ? I also have this problem
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));
There Will you two R.id.tab1, R.id.tab2 in the xml file is how the definition of ?
------ For reference only -------------------------------------- -
which class you inherited

没有评论:

发表评论