[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]
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]