Android Learning Note--listview

Source: Internet
Author: User

The function of the project is to implement a table displayed in an activity

The following code is the code in Mainactivity.java

 PackageCom.example.listview;Importjava.util.ArrayList;ImportJava.util.HashMap;Importandroid.app.ListActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.widget.SimpleAdapter; Public classMainactivityextendslistactivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                        Setcontentview (R.layout.activity_main); ArrayListNewArraylist(); HashMap<string, string> map1 =NewHashmap<string,string>(); HashMap<string, string> map2 =NewHashmap<string,string>(); HashMap<string, string> map3 =NewHashmap<string,string>(); Map1.put ("User_name", "Zhangsan"); Map1.put ("User_ip", "192.168.0.1"); Map2.put ("User_name", "Lisi"); Map2.put ("User_ip", "192.168.0.2"); Map3.put ("User_name", "Wangwu"); Map3.put ("User_ip", "192.168.0.3");        List.add (MAP1);        List.add (MAP2);                List.add (MAP3); Simpleadapter ListAdapter=NewSimpleadapter ( This, List, R.layout.activity_user,NewString[] {"user_name", "USER_IP"},                New int[] {r.id.user_name, r.id.user_ip});    Setlistadapter (ListAdapter); }}

The following code is the code in Activity_main.xml

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/linearlayout1"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Vertical"Tools:context= "${relativepackage}.${activityclass}" > <LinearLayout Android:id= "@+id/listlinearlayout"android:orientation= "Vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content" > <ListView Android:id= "@id/android:list"Android:scrollbars= "Vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:drawselectorontop= "false"/> </LinearLayout></LinearLayout>

The following code is the code in Activity_user.xml

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/linearlayout2"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Horizontal"Android:paddingleft= "10dip"Android:paddingright= "10dip"Android:paddingtop= "1dip"Android:paddingbottom= "1dip"Tools:context= "${relativepackage}.${activityclass}" > <TextView Android:id= "@+id/user_name"Android:layout_width= "180dip"Android:layout_height= "30dip"android:textsize= "10pt"Android:singleline= "true"/> <TextView Android:id= "@+id/user_ip"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:gravity= "Right"android:textsize= "10pt"/></linearlayout>

Android Learning Note--listview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.