何谓 AdapterView 以前有说过 就是如下几个View:
写道
ListView
Gallery
GridView
Spinner
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 运行截图为:

本文介绍了如何在Android应用中自定义AdapterView来显示多个TextView。通过创建自定义布局文件simple_adapter_g3.xml,可以灵活地调整每个TextView的样式及布局,并通过SimpleAdapter将数据绑定到这些视图上。
377

被折叠的 条评论
为什么被折叠?



