一直在玩Android并使用各种资源提出了这个列表:
public class TestingList extends ListActivity {
private static final String ICON_KEY = "icon";
private static final String TITLE_KEY = "title";
private static final String DETAIL_KEY = "detail";
private static final int[] ICONS = new int[] { R.drawable.lista,
R.drawable.listb, R.drawable.listc, R.drawable.listd };
private static final String[] TITLES = new String[] { "List 1", "List 2",
"List 3", "List 4" };
private static final String[] DETAILS = new String[] {
"List 1 description, a little more text here please, just testing how it reacts to more.",
"List 2 description, a little more text here please, just testing how it reacts to more.",
"List 3 description, a little more text here please, just testing how it reacts to more.",
"List 4 description, a little more text here please, just testing how it reacts to more." };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
for (int i = 0; i < ICONS.length; i++) {
rows.add(createListItemMap(ICONS[i], TITLES[i],
DETAILS[i]));
}
// set up SimpleAdapter for icon_detail_list_item
String[] fromKeys = new String[] { ICON_KEY, TITLE_KEY, DETAIL_KEY };
int[] toIds = new int[] { R.id.icon, R.id.text1, R.id.text2 };
setListAdapter(new SimpleAdapter(this, rows,
R.layout.icon_detail_list_item, fromKeys, toIds));
}
我想了解一下如何将列表分隔符添加到此列表中,完成此操作的最佳方法是什么。最终列表将包含更多项目,但我想在某些点上命名分隔符。
答案 0 :(得分:0)
如果你想添加一个对于每一行都相同的单个分隔符而不是简单的分隔符。你只需在列表中调用setDivider(Drawable)并添加代表你的分隔符的drawable。
如果你想按像divider这样的类别划分列表,那么事情会变得更复杂。
@CommonsWare有一个很好的演示和一个如何在他的cwac-Merge项目中实现这个目标的库。
这是一个链接:Cwac
答案 1 :(得分:0)