2011-06-18 37 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