[英]Custom widget ListView not working properly
I have a widget with a ListView, that has custom list items, implemented with RemoteViewsService.RemoteViewsFactory
. 我有一个带有ListView的小部件,该小部件具有自定义列表项,并通过RemoteViewsService.RemoteViewsFactory
实现。 My layout code is this: 我的布局代码是这样的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<View
android:layout_width="10dp"
android:layout_height="match_parent"
android:background="#dabcee" />
<TextView
android:id="@+id/widgetRow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:textColor="#333"
android:textSize="20sp"
android:drawableRight="@drawable/ic_action_next_item"/>
</LinearLayout>
The problem with this layout is that it's not working, it displays "Loading..." for every list item. 此布局的问题是它无法正常工作,它为每个列表项显示“正在加载...”。 The thing is, if i remove the first View
that acts just as a design element and adds a coloured bar at the begining of each item.... it works. 问题是,如果我删除了仅用作设计元素的第一个View
,并在每个项目的开头添加了彩色条...。 How can i make it work with the first View
? 如何使它与第一个View
?
Thanks! 谢谢!
I fixed this by changing the first View
to a LinearLayout
, it seemed to work after that. 我通过将第一个View
更改为LinearLayout
来解决此问题,此后它似乎可以工作了。 However, i am still not sure why this works, if anyone knows, please leave a comment. 但是,我仍然不确定为什么会这样,如果有人知道,请发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.