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?
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 equalsnoneaccording to the xml file declaring the attributes.and
The documentation states that
remove_mode=nonemeans that the user cannot remove any list entries.Now, as far as I know, you cannot create an
AttributeSetwithout using xml. If you really don’t want to use any xml files, then you should probably adapt theTouchListViewclass and add the necessary getters and setters.