0

I'm trying to use the TouchListView made available here: https://github.com/commonsguy/cwac-touchlist. It's an Android library to create reorderable lists.

I can run the demo fine, but I can't find a way to create a TouchList in Java, ie without defining it in an XLM layout.

Here's the code from the demo:

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    TouchListView tlv=(TouchListView)getListView();
    adapter=new IconicAdapter();
    setListAdapter(adapter);

    tlv.setDropListener(onDrop);
    tlv.setRemoveListener(onRemove);
}

It's inside a ListActivity. That works fine. Now here what I've tried to avoid the use of a ListActivity:

...
TouchListView tlv = new TouchListView(this, null);
adapter=new IconicAdapter();
setListAdapter(adapter);
...

No luck.

LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
TouchListView tlv = (TouchListView) (inflater.inflate(R.layout.touchlistview, null));

Doesn't work either.

In both cases the list is displayed correctly but I can't move the items around.

Any idea?

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
MasterScrat
  • 7,090
  • 14
  • 48
  • 80
  • 1
    Well, the first case won't work, as there are various attributes (see the `tlv` ones in the `demo/`) that are needed. The second one might work, depending on the contents of `R.layout.touchlistview`, if you eventually add the `TouchListView` to a parent container somewhere along the line. – CommonsWare Nov 05 '11 at 22:10
  • Thanks. The problem was that my grabber id was wrong :/ BTW, is there a way to have items of different sizes in the list? I have some multiline entries and they get resized to single line as soon as I move something. – MasterScrat Nov 05 '11 at 22:55
  • Not really AFAIK. This code is just adapted from some stuff from the AOSP Music app, which didn't have varying-size rows. There is the notion of expanding a row when you drag over it -- I just updated the sample to better demonstrate that. However, I think the code assumes the rows are otherwise the same size. – CommonsWare Nov 05 '11 at 23:00

1 Answers1

1

The issue is probably that you're not setting any of the attributes, as you pass in null.

By default the variable controlling the remove mode is set to -1, which equals none according to the xml file declaring the attributes.

private int mRemoveMode = -1;

and

<attr name="remove_mode">
    <enum name="none" value="-1" />
    ...
</attr>

The documentation states that remove_mode=none means that the user cannot remove any list entries.

Now, as far as I know, you cannot create an AttributeSet without using xml. If you really don't want to use any xml files, then you should probably adapt the TouchListView class and add the necessary getters and setters.

MH.
  • 45,303
  • 10
  • 103
  • 116