android¿Ø¼þ¿ª·¢Ö®ListView

來源:互聯網
上載者:User

android¿Ø¼þ¿ª·¢ÖListView
android¿Ø¼þ¿ª·¢ÖListView

±¾ÎÄÖ÷Òª½²Êö°²×¿¿ª·¢ÖеÄListView¿Ø¼þµÄʹÓ÷½·¨

java´úÂ룺package com.example.listview;


import java.util.ArrayList;
import java.util.HashMap;


import android.app.ListActivity;
import android.os.Bundle;


import android.view.Menu;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;


public class MainActivity extends ListActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//ÉùÃ÷list£¬ÇÒlistÖеĵ¥ÔªÊÇmap
ArrayList> list = new ArrayList>();

//ÉùÃ÷map£¬ÇÒmapÖеÄÔªËØÊÇString¼ü值¶Ô
HashMap map1 = new HashMap();
HashMap map2 = new HashMap();
HashMap map3 = new HashMap();

//ÏòmapÖÐput¼ü值¶ÔÊý¾Ý
map1.put("name", "zhangsan");
map1.put("ip", "192.168.1.1");
map2.put("name", "lisi");
map2.put("ip", "192.168.1.2");
map3.put("name", "wangwu");
map3.put("ip", "192.168.1.3");

//½«mapÌí¼Óµ½listÖÐ
list.add(map1);
list.add(map2);
list.add(map3);

//Éú³ÉadapterÊÊÅäÆ÷
SimpleAdapter listAdapter = new SimpleAdapter(this, list,
R.layout.user, new String[]{"name","ip"},
new int[]{R.id.name,R.id.ip});
setListAdapter(listAdapter);


}

//¸ølist°ó¶¨¼àÌýÆ÷£¬µ±°´ÏÂlistÖÐijһ¸öµ¥ÔªÊ±£¬¾Í»áÏàÓ¦´Ëº¯Êý
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
System.out.println("id = " + id);
System.out.println("position = " + position);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


}


Ö÷²¼¾ÖÎļþmail.xml´úÂ룺
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />


android:id="@+id/listLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"

>

android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical">






user.xml´úÂëʵÏÖ£º

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mapLinear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
tools:ignore="UselessParent" >



android:id="@+id/name"
android:layout_width="180dip"
android:layout_height="30dip"
android:textSize="20dip"
android:gravity="center_vertical"/>



android:id="@+id/ip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dip"/>



ʵÏÖЧ¹ûÈçÏ£º

<†·Ÿ"http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPgo8c3Ryb25nPrXju/fP4LnYtcRsaXN0wdCx7aOs1NpMb2dDYXTW0LvhyuSz9s/gudi1xGxpc3TQxc+iyOfPwqO6PC9zdHJvbmc+CjxzdHJvbmc+PGltZyBzcmM9"" alt="">

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.