2011-06-18 38 views
0

已经与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

如果你想添加一个单独的分隔线,每行都是相同的,而不是那么简单。您只需在列表中调用setDivider(Drawable)并添加将代表您的分隔符的drawable。

如果你想按分类器的类别划分列表,那么事情会变得更加复杂。

@CommonsWare有一个很好的演示和如何在他的cwac-Merge项目中实现这个库。

这里是一个链接:Cwac