Implementation of the ListView based on Baseadapter
Note the following four methods need to be rewritten to extend Baseadapter
GetCount ();
GetItem ();
Getitemid ();
GetView ();
List of programs
Package xiaocool.net.listviewtest;import android.graphics.color;import android.os.bundle;import android.support.v7.app.ActionBarActivity;import android.view.View;import Android.view.viewgroup;import android.widget.baseadapter;import android.widget.imageview;import android.widget.LinearLayout;import android.widget.ListView;import android.widget.TextView; public class mainactivity extends actionbaractivity { private listview list; @Override protected void oncreate ( Bundle savedinstancestate) { super.oncreate ( Savedinstancestate); setcontentview (R.LAYOUT.LISTVIEW2); list= (ListView) This.findviewbyid (r.id.list1); /*//defines an array string arr[]={"School Cool Network 1", "School Cool Network 2", "School Cool Network 3", "School Cool Network 4", "School Cool network 5"}; //wrapping an array into a arrayadapter arrayadapter <String> adapter=new ArrayAdapter<String> (This,r.layout.array_item,r.id.textview,arr); list.setadapter (Adapter);*/ baseadapter adapter=new baseadapter () { //returns the total number of list items @Override public int getcount () { return 20; } @Override public object getitem (int position) { return null; } //returns the ID of a list item @Override public long getitemid (int position) { return 0; } //returns the appearance of each specific item @Override public view getview (int position, View convertview, viewgroup parent) { //Create a LinearLayout and add two controls to it linearlayout layout=new linearlayout ( Mainactivity.this); layout.setorientation (0); imageview imageview=new imageview (mainactivity.this); imageview.setimageresource ( R.drawable.syudio); textview textview=new texTView (mainactivity.this); textview.settext ("position+1" + "item"); textview.settextcolor (Color.Blue); textview.settextsize (; ) layout.addview (ImageView); layout.addview ( TextView); return layout; } }; list.setadapter (adapter); }}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/41/wKioL1UD7bqj2Sr1AAJvTv38BmU388.jpg "title=" Screenshot_2015-03-14-16-07-49.png "alt=" Wkiol1ud7bqj2sr1aajvtv38bmu388.jpg "/>
Use of Android learning--listview (iv)