自定义 AdapterView 布局

 何谓 AdapterView 以前有说过 就是如下几个View:

写道
ListView
Gallery
GridView
Spinner

 

 

至于布局 系统已经为我们定义了一下 比如:

android.R.layout.simple_list_item_1
android.R.layout.simple_list_item_2
android.R.layout.simple_list_item_3
...

 

 

但是系统肯定不能满足我们的需要 所以有时候我们得根据界面的需要自定义 这有2种方法:

 

1. 自定义BaseAdapter 并实现其 getView()

但是 有时候 我们要显示的数据源也是其支持的TextView 自定义BaseAdapter 好像有点舍本逐末了 得不偿失 

 

2. 自定义界面 然后在Adapter中使用之

 

写道
Adapter 显示中 每一行就是一个View 你可以把这个View 定义成任何子布局

 

 

* 现在有程序要求显示3个TextView  假设该布局如下:simple_adapter_g3.xml

 

 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="wrap_content"
	android:stretchColumns="0" android:padding="5dp">
		<LinearLayout 
		android:orientation="horizontal" >
			<TextView
				android:id="@+id/text1" 
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:textSize="16sp"
				android:textColor="#FFC8FF"
				android:textStyle="bold|italic" />
			<TextView
				android:id="@+id/text3"
				android:layout_width="wrap_content" 
				android:layout_height="fill_parent"
				android:textSize="16sp"
				android:layout_marginLeft="50px" />
		</LinearLayout>
		<TextView
				android:id="@+id/text2" 
				android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				 android:textSize="16sp" 
				 android:textStyle="bold"/>
</TableLayout>

 

* 如何使用

 

String[] from={COLUMN_1,COLUMN_2,COLUMN_3};
        int[] to={R.id.text1,R.id.text2, R.id.text3};
        
		SimpleAdapter adapter = new SimpleAdapter(this,people,R.layout.simple_adapter_g3,from,to);

 

 

* emulator 运行截图为:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值