0

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

});
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Eljas
  • 1,187
  • 4
  • 17
  • 37

1 Answers1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So if I want to get my links open from right item I have drag and drop links same time than I drag and drop my items. Like I have to get them same drag and drop and anytime I move item two rows down it moves link two rows down too? If you understand what I trying to say. :) – Eljas Feb 14 '12 at 00:29
  • @Eljas: I am afraid that I do not understand what you are trying to say. – CommonsWare Feb 14 '12 at 00:37
  • Right now i have my items and links like this: `private static String[] items={"Google", "Yahoo"}; private static String[] links={"http://google.com", "http://yahoo.com"};` So is it impossible this way to get links open from right item when you change items order? – – Eljas Feb 14 '12 at 00:59
  • 1
    @Eljas: You cannot change the order of a `String[]`. Make an `ArrayList` that holds onto the name and the URL, and change the order of items in the `ArrayList` when the user changes the order of the items in the `TouchListView`. This is what the demo app shows. – CommonsWare Feb 14 '12 at 11:49
  • I don't know how to do this: **"Store the order somewhere (e.g., sequence column in your database table) and re-order the data when loading it back into your Adapter."** And I appreciate if you have little bit time to help me with this. Like if you know any tutorials what gives me more information or something. You can find code what im using right now from here: [link](http://pastebin.com/znZmsDMk) – Eljas Feb 17 '12 at 02:34
  • @CommonsWare can you please look over this `http://stackoverflow.com/questions/15719106/touchlistview-is-not-working-when-parent-activity-finishes` – Hunt Mar 31 '13 at 05:38