Create a ListView based on Arrayadapter
List of programs
Listview2.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "> <listview android:la Yout_width= "Wrap_content" android:layout_height= "wrap_content" android:id= "@+id/list1" android:divide R= "#0f0" android:dividerheight= "3px" android:footerdividersenabled= "false"/></linearlayout> ;
Mainactivity.java
package xiaocool.net.listviewtest;import android.os.bundle;import android.support.v7.app.actionbaractivity;import android.widget.arrayadapter;import android.widget.listview;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); }}
Array_item. Xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "> <textview android:la Yout_width= "Fill_parent" android:layout_height= "wrap_content" android:id= "@+id/textview" Android:text Size= "20SP" android:textcolor= "#f0f" android:padding= "20px"/></linearlayout>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/43/wKiom1UDkHeBUIooAAFYZ2kk_-k792.jpg "title=" Qq20150314093422.png "alt=" Wkiom1udkhebuiooaafyz2kk_-k792.jpg "/>
Use of Android learning--listview (ii)