开发者

Adding List separators in an existing list

Been playing around with Android and using various resources have come up with this list:

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));




    }

I'd like to some how add list separators to this list, what would the best way to get that done. The final list will have a lot more items, but I'd like named separators at certain points.


if you want to add a single divider that will be the same for each row than that is simple. you just call setDivider(Drawable) on your list and add the drawable that will represent your divider.

If you want to divide the list by categories like divider then things get more complicated.

@CommonsWare has a nice demo and a library of how to achieve this in his cwac-Merge project.

here is a link: Cwac


have a look at SeperatedListAdapter or android-section-list

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜