Day 10 of Android-simple implementation of listview

Source: Internet
Author: User

Main. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: Orientation = "vertical">


<Listview
Android: Id = "@ ID/Android: List"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "vertical"

/>


</Linearlayout>

User. 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"
Android: Orientation = "horizontal">

<Textview
Android: Id = "@ + ID/user_name"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textsize = "10pt"
/>

<Textview
Android: Id = "@ + ID/user_ip"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"

Android: textsize = "10pt"
Android: singleline = "true"
/>

</Linearlayout>

Listview_testactivity.java

 

Package CN. class3g. activity;

Import java. util. arraylist;
Import java. util. hashmap;

Import Android. App. listactivity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. listview;
Import Android. widget. simpleadapter;
Import Android. widget. Toast;

Public class listview_testactivity extends listactivity {


Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Arraylist
Hashmap <string, string> map1 = new hashmap <string, string> ();
Hashmap <string, string> MAP2 = new hashmap <string, string> ();
Hashmap <string, string> map3 = new hashmap <string, string> ();

Map1.put ("user_name", "Zhang San ");
Map1.put ("user_ip", "192.168.65.22 ");


Map2.put ("user_name", "Li Si ");
Map2.put ("user_ip", "192.168.65.32 ");


Map3.put ("user_name", "Wang Wu ");
Map3.put ("user_ip", "192.168.65.42 ");

List. Add (map1 );
List. Add (MAP2 );
List. Add (map3 );



Simpleadapter adapter = new simpleadapter (this, list, R. layout. user,
New String [] {"user_name", "user_ip"}, new int [] {R. Id. user_name, R. Id. user_ip });


Setlistadapter (adapter );
}

Protected void onlistitemclick (listview L, view V, int position, long ID ){
 
Super. onlistitemclick (L, V, position, ID );

Toast. maketext (this, String. valueof (position), Toast. length_short). Show ();
}






}

 

Related Article

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.