如何在日常活动中使用公共软件
我有一个已经建立的活动,必须扩展另一个活动,所以我宁愿使用公共软件拖放 TouchListView 类与我现有的活动,而不是扩展 ListActivity。但是,我找不到如何执行此操作的示例。在我的活动的 xml 中,我包含了:
<com.test.dragdrop.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/com.test.activities"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
tlv:normal_height="64dip"
tlv:expanded_height="128dip"
tlv:grabber="@+id/icon"
tlv:remove_mode="slideRight"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@id/menu_bar_top_include"
android:layout_above="@id/footerbar_lists"
android:cacheColorHint="#0000"
android:paddingTop="2dip"/>
现在,我不确定如何将其转换为在我的活动代码中动态创建它。我假设我必须将代码放在 onCreate() 中并创建一个relativelayout包装器并将TouchListView类放入其中,但我再次不确定何时涉及自定义视图类...有人这样做过吗?
注意:我也尝试简单地使用:
TouchListView tlv = (TouchListView) findViewById(R.id.list);
但我收到编译器错误:
--- 由于某种原因,编译器找不到“R.id.list” --- 这是因为它位于自定义视图内吗?是否需要通过其他方式指定?
I have an already established activity that must extend another activity so I'd much rather use commonsware drag and drop TouchListView class with my existing activity rather than extend ListActivity. However, I can't find an example of how to do this. In my activity's xml I have included:
<com.test.dragdrop.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/com.test.activities"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
tlv:normal_height="64dip"
tlv:expanded_height="128dip"
tlv:grabber="@+id/icon"
tlv:remove_mode="slideRight"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@id/menu_bar_top_include"
android:layout_above="@id/footerbar_lists"
android:cacheColorHint="#0000"
android:paddingTop="2dip"/>
Now, I'm not sure how translate this to creating it dynamically in my actvities code . I assume I have to place the code in onCreate() and create a RelativeLayout wrapper and put the TouchListView class inside of it, but again I'm not sure when it comes to a custom view class... any one do this before?
Note: I also tried to simply use :
TouchListView tlv = (TouchListView) findViewById(R.id.list);
but I get compiler errors:
--- for some reason the compiler cannot find "R.id.list" --- Is this because its inside a custom view? Is there some other way this needs to be specified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在常规 Activity 中使用
TouchListView
与在常规 Activity 中使用ListView
没有什么不同。您要做的就是调用findViewById()
来获取 ListView,并在ListView
上调用setAdapter()
来关联您想要的ListAdapter< /代码> 与它。
There is nothing different about using
TouchListView
in a regular Activity than usingListView
in a regular Activity. All you do is callfindViewById()
to get the ListView and callsetAdapter()
on theListView
to associate your desiredListAdapter
with it.