The example in this article describes how Android implementations add multiple ListView to an activity. Share to everyone for your reference, specific as follows:
ListView's ID is generally like this android:id= "@id/android:list". Note that the activity at this time is listactivity, and so far I have found no way to add more than one activity. To add multiple listview, the activity used if the general Activity,listview ID also to define themselves, to Android:id= "@+id/mylist." And then, like using a generic control, initialization is OK. As for adapter I inherited the Baseadapter, define a adapter for each ListView, and then the corresponding settings adapter on it.
Reference code:
public class MyActivity extends activity implements Onclicklistener {private listviewlistview_psychologicalstate,
Listview_weatherstate;
Private ListAdapter listadapter_psychologicalstate,listadapter_weatherstate; Private arraylist<string> Psychologicalstatearray = new arraylist<string> (), Weatherstatearray = new
Arraylist<string> ();
Private String [] strpsychologicalstate = new string[]{"Depressed", "hyper", "pressure", "insomnia", "drowsiness", "easy to Panic"};
Private String [] strweatherstate = new string[]{"Hot and humid", "hot", "cold"}; @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.personalizedorderview);
Findview ();
public void Findview () {listview_psychologicalstate = (ListView) Findviewbyid (R.id.psychologicalstatelistid);
Listview_weatherstate = (ListView) Findviewbyid (R.id.weatherstatelistid);
for (int i = 0;i<strpsychologicalstate.length;i++) Psychologicalstatearray.add (Strpsychologicalstate[i]); for (int i = 0;i<strweatherstate.length; i++) Weatherstatearray.add (Strweatherstate[i]);
Listadapter_psychologicalstate = new Getinflamedadapter (This,psychologicalstatearray);
Listview_psychologicalstate.setadapter (listadapter_psychologicalstate);
Listadapter_weatherstate = new Getinflamedadapter (This,weatherstatearray);
Listview_weatherstate.setadapter (listadapter_weatherstate); public class Getinflamedadapter extends Baseadapter {private context; private layoutinflater minflater; private
Arraylist<string> ArrayList; Public Getinflamedadapter (Context context,arraylist<string> ArrayList) {this.context=context; this.arraylist =
ArrayList
Minflater = (layoutinflater) this.context.getSystemService (Context.layout_inflater_service); @Override public int GetCount () {//TODO auto-generated a stub return Arraylist.size ();} @Override the public Object GetItem (int position) {//TODO auto-generated Method stub return Arraylist.get (position);} @Override public Long GetItem Id (int position) {//TODO auto-Generated method stub return position; @Override public View getview (int position, View Convertview, ViewGroup parent) {//TODO auto-generated method stub con
Vertview = minflater.inflate (r.layout.inflamedchild, NULL);
Viewholder viewholder = null;
Viewholder = new Viewholder ();
Viewholder.label = (TextView) Convertview.findviewbyid (R.ID.BODYSTATEID1);
ViewHolder.label.setText (Arraylist.get (position). ToString ());
ViewHolder.label.setTextColor (Color.green);
ViewHolder.label.setTextSize (22);
Convertview.settag (Viewholder);
return convertview;
Private class Viewholder {TextView label;}}
For more information on Android-related content readers can view the site: "The activity of Android programming skills Summary", "Android View Summary", "Android operation SQLite Database Skills Summary", " Android operation JSON format data tips summary, "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card Operation Summary", "Android Development introduction and Advanced Course", " Android Resource Operation tips Summary and the "Android Controls usage Summary"
I hope this article will help you with the Android program.