Drag and Drop with cwac-touchlist

血红的双手。 提交于 2019-12-13 07:15:42

问题


I have two questions.

1. How to make app remember new order in ListView what I made with drag and drop. Like now I can reorder items but every time I open app, I have to reorder items again.

2. My app should open different webpage from each item. But when I reorder items then web links doesn't reorder. They stick on same.

Like example: I have items Google and Yahoo! so links are "http://google.com" and "http://yahoo.com". Then I reorder item: Google was top but I drag Yahoo to top. After that when I press "Yahoo!" item it open Google's website and when I press "Google" it opens Yahoo's website.

Here is how I have made OnItemClickListener:

getListView().setOnItemClickListener(new OnItemClickListener() {


    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
        String content = links[position];
        Intent showContent = new Intent(getApplicationContext(),
                Web.class);
        showContent.setData(Uri.parse(content));
        startActivity(showContent);
    }

});

回答1:


How to make app remember new order in ListView what I made with drag and drop. Like now I can reorder items but every time I open app, I have to reorder items again.

Store the order somewhere (e.g., sequence column in your database table) and re-order the data when loading it back into your Adapter.

My app should open different webpage from each item. But when I reorder items then web links doesn't reorder. They stick on same.

Quoting the documentation:

In code, you set up a TouchListView just like a regular ListView, except that you need to register a TouchListView.DropListener via setDropListener(). In your listener, you will need to do something to affect the re-ordering requested via the drag-and-drop operation. In the demo project, this is a matter of removing the entry from the old position and putting it in the new position.



来源:https://stackoverflow.com/questions/9204485/drag-and-drop-with-cwac-touchlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!