直接说过程吧:

[size=large]直接说过程吧:
1.构建一个HashMap:
Java代码
ArrayList<HashMap<String, String>> dlist = new ArrayList<HashMap<String, String>>();

for (int i = 0; i < data.length; i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("data", data[i]);
dlist.add(map);
}

ArrayList<HashMap<String, String>> dlist = new ArrayList<HashMap<String, String>>();

for (int i = 0; i < data.length; i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("data", data[i]);
dlist.add(map);
}


2.设置SimpleAdapter:
Java代码
SimpleAdapter adapter = new SimpleAdapter(this, dlist,
R.layout.list_item, new String[] { "data" },
new int[] { R.id.entries });

list.setAdapter(adapter);

SimpleAdapter adapter = new SimpleAdapter(this, dlist,
R.layout.list_item, new String[] { "data" },
new int[] { R.id.entries });

list.setAdapter(adapter);


3.主要在list_item上:
Java代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/selector">
<TextView android:text="data" android:id="@+id/entries"
android:layout_width="match_parent" android:layout_height="wrap_content">
</TextView>
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/selector">
<TextView android:text="data" android:id="@+id/entries"
android:layout_width="match_parent" android:layout_height="wrap_content">
</TextView>
</LinearLayout>


4.上述item上设置了背景:selector.xml:
Java代码
<item android:state_selected="true">
<shape>
<gradient android:angle="270" android:endColor="#ffffffff"
android:startColor="#ffffffff" />
<padding android:left="15dp" android:top="20dp"
android:right="15dp" android:bottom="20dp" />

<size android:height="60dp" android:width="320dp" />

<corners android:radius="8dp" />

</shape>
</item>

<item android:state_selected="true">
<shape>
<gradient android:angle="270" android:endColor="#ffffffff"
android:startColor="#ffffffff" />
<padding android:left="15dp" android:top="20dp"
android:right="15dp" android:bottom="20dp" />

<size android:height="60dp" android:width="320dp" />

<corners android:radius="8dp" />

</shape>
</item>


"android:state_selected="true""这个属性还有:"android:state_pressed="true""或者不设置表示默认的时候背景情况.

我写在这里是为了后续编码的时候参考的......:) [/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值