Eljas
Eljas

Reputation: 1207

Drag and Drop with cwac-touchlist

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

});

Upvotes: 0

Views: 439

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007534

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.

Upvotes: 1

Related Questions