Monday, April 14, 2014

Tab in a TabHost the page you want to display a ListView, why not come out?


The following code, but does not show on the Tab after running out there 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);

}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
I usually rewrite the adapter, and then implement getView, then setAdapter
Reply:
Should be the adapter, a floor right, a custom adapter will be better
Reply:
Which version you use?

Every time you must use the new hash map object to store data
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);








Reply:
Will 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?
Reply:
Which class you inherit

No comments:

Post a Comment