Android学习笔记06:ListView的使用
【摘要】
[Android开发视频教学].01_13_Android常见控件(三)之二 学习使用ListView
list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schem...
[Android开发视频教学].01_13_Android常见控件(三)之二 学习使用ListView
list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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:drawSelectorOnTop="false"
android:scrollbars="vertical" >
</ListView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/user_ip"
android:layout_width="180dp"
android:layout_height="20dp"
android:gravity="left" />
<TextView
android:id="@+id/user_name"
android:layout_width="fill_parent"
android:gravity="right"
android:layout_height="20dp" />
</LinearLayout>
package fengda.android09;
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;
public class Activity09 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity09);
ArrayList<HashMap<String, String>> mapList = new ArrayList<HashMap<String, String>>();
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("usr_ip", "192.168.0.1");
map1.put("user_name", "一号");
map2.put("user_ip", "192.168.0.2");
map2.put("user_name", "二号");
map3.put("user_ip", "192.168.0.3");
map3.put("user_name", "三号");
mapList.add(map1);
mapList.add(map2);
mapList.add(map3);
SimpleAdapter ad = new SimpleAdapter(this, mapList, R.layout.user,
new String[] { "user_ip", "user_name" }, new int[] {
R.id.user_ip, R.id.user_name });
this.setListAdapter(ad);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
文章来源: blog.csdn.net,作者:fengda2870,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/fengda2870/article/details/8161598
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)