以编程方式创建 TouchList
我正在尝试使用此处提供的 TouchListView: https://github.com/commonsguy/cwac-touchlist 。它是一个用于创建可重新排序列表的 Android 库。
我可以很好地运行演示,但我找不到在 Java 中创建 TouchList 的方法,即不在 XLM 布局中定义它。
以下是演示中的代码:
@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);
}
它位于 ListActivity 内。效果很好。现在,我尝试避免使用 ListActivity:
...
TouchListView tlv = new TouchListView(this, null);
adapter=new IconicAdapter();
setListAdapter(adapter);
...
没有运气。
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
TouchListView tlv = (TouchListView) (inflater.inflate(R.layout.touchlistview, null));
也不行。
在这两种情况下,列表都显示正确,但我无法移动项目。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是您在传入
null
时没有设置任何属性。默认情况下,控制删除模式的变量设置为
-1
,根据声明属性的 xml 文件,该变量等于none
。文档
指出
remove_mode=none
表示用户无法删除任何列表条目。现在,据我所知,如果不使用 xml,则无法创建 AttributeSet。如果您确实不想使用任何 xml 文件,那么您可能应该调整
TouchListView
类并添加必要的getter 和setter。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 equalsnone
according to the xml file declaring the attributes.and
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 theTouchListView
class and add the necessary getters and setters.