ANDROID_MARS学习笔记_S01原始版_006_ListView
一、代码
1.xml
(1)main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/listLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="true"
android:scrollbars="vertical" />
</LinearLayout>
</LinearLayout>
(2)user.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="horizontal" android:paddingLeft="10dip"
android:paddingRight="10dip" android:paddingTop="1dip"
android:paddingBottom="1dip">
<TextView android:id="@+id/user_name" android:layout_width="180dip"
android:layout_height="30dip" android:textSize="5pt"
android:singleLine="true" />
<TextView android:id="@+id/user_ip" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="right"
android:textSize="5pt" />
</LinearLayout>
2.java
(1)Activity01.java
package mars.listview; 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 Activity01 extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> list = 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("user_name", "zhangsan");
map1.put("user_ip", "192.168.0.1");
map2.put("user_name", "zhangsan");
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);
MyAdapter listAdapter = new MyAdapter(this, list,
R.layout.user, new String[] { "user_name", "user_ip" },
new int[] { R.id.user_name,R.id.user_ip});
setListAdapter(listAdapter);
} @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);
} }
(2)MyAdapter.java
package mars.listview; import java.util.List;
import java.util.Map; import android.R.color;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter; public class MyAdapter extends SimpleAdapter {
private LayoutInflater inflater = null;
private List<Map<String,Object>> styles = null;
public List<Map<String, Object>> getStyles() {
return styles;
} public void setStyles(List<Map<String, Object>> styles) {
this.styles = styles;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View result = super.getView(position, convertView, parent);
System.out.println("positon---->" + position);
if(result != null){
inflater.inflate(R.layout.user1, null);
}
return result;
} public MyAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
inflater = LayoutInflater.from(context);
} }
ANDROID_MARS学习笔记_S01原始版_006_ListView的更多相关文章
- ANDROID_MARS学习笔记_S01原始版_005_RadioGroup\CheckBox\Toast
一.代码 1.xml(1)radio.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- ANDROID_MARS学习笔记_S01原始版_004_TableLayout
1.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android ...
- ANDROID_MARS学习笔记_S01原始版_003_对话框
1.AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest ...
- ANDROID_MARS学习笔记_S01原始版_002_实现计算乘积及menu应用
一.代码 1.xml(1)activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...
- ANDROID_MARS学习笔记_S01原始版_001_Intent
一.Intent简介 二.代码 1.activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.co ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER005_用广播BroacastReciever实现后台播放不更新歌词
一.代码流程1.自定义一个AppConstant.LRC_MESSAGE_ACTION字符串表示广播"更新歌词" 2.在PlayerActivity的onResume()注册Bro ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER004_同步显示歌词
一.流程分析 1.点击播放按钮,会根据lrc名调用LrcProcessor的process()分析歌词文件,得到时间队列和歌词队列 2.new一个hander,把时间队列和歌词队列传给自定义的线程类U ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER003_播放mp3
一.简介 1.在onListItemClick中实现点击条目时,跳转到PlayerActivity,mp3info通过Intent传给PlayerActivity 2.PlayerActivity通过 ...
- ANDROID_MARS学习笔记_S01原始版_022_MP3PLAYER002_本地及remote标签
一.简介 1.在main.xml中用TabHost.TabWidget.FrameLayout标签作布局 2.在MainActivity中生成TabHost.TabSpec,调用setIndicato ...
随机推荐
- AlwaysOn实现只读路由
1.配置只读路由 ①配置A副本的只读路由属性(ReadOnly代表‘只读意向’) ALTER AVAILABILITY GROUP [testAG] MODIFY REPLICA ON N'WIN-1 ...
- SQL Server 可疑的解决办法
SQL SERVER 数据库状态为“可疑”的解决方法 --MyDB为修复的数据名 USE MASTER GO SP_CONFIGURE RECONFIGURE WITH OVERRIDE GO ALT ...
- Install GTK in Ubuntu
reference: http://www.cnblogs.com/niocai/archive/2011/07/15/2107472.html 一.安装 1.安装gcc/g++/gdb/make 等 ...
- 三【相关度 相似度查询与计算】相似度到大数据查找之Mysql 文章匹配的一些思路与提高查询速度
记录下,在上2回的数据基础之上,附带一个互信息(MI,Mutual Information)可以计算词之间的相关度 标准互信息 MI(X,Y)=log2p(x,y)/p(x)p(y) 值越大于0 则趋 ...
- 高能物理/HyperPhysics的网站/Website
参考: 基础物理-高能物理[Hyperphysics]
- Windows 键盘操作快捷方式积累
复制.粘贴: CTRL+C 复制被选择的项目到剪贴板 CTRL+V 粘贴剪贴板中的内容到当前位置 CTRL+X 剪切被选择的项目到剪贴板 Alt+ space + E + P CMD 窗口快速粘贴 关 ...
- 学习笔记---C++虚函数,纯虚函数
1 .虚函数 假设people是man的父类,people类和man类都定义了实函数walk() people* p = new man(); p->walk(); 这里P执行的是people类 ...
- hdu 1316 How many Fibs?(高精度斐波那契数)
// 大数继续 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn : ...
- Android_Json实例
概要: 最近由于自己的兴趣,想在Android开发一个自己的App,需要使用服务器,所以交换数据是逃不掉了的,但是学生党没有固定的服务器,因此使用的新浪的SAE,在学习的前期下可以尝试一下,挺不错的一 ...
- 【原创】一起学C++ 之 字符串 ---------C++ primer plus(第6版)
C++ Primer Plus 第6版 字符串:是存储在内存的连续字节中的一系列字符. C++处理字符串的方式有2种: 一.来自C语言.常被称为C-风格字符串(C-Style-string) 1)从字 ...