Android所有小部件列表页面,主屏幕小部件,listView显示“正在加载”

首先,一张图片说千言万语:

h1ugR.png

虽然getViewAt被称为4项,但是我的光标大小是这样的。

这是代码:

public class WidgetService extends RemoteViewsService { @Override public RemoteViewsFactory onGetViewFactory(Intent intent) { System.out.println("Factory"); return(new WidgetViewsFactory(this.getApplicationContext(), intent)); } }

小部件提供者:

public class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory, LNTConstants { private Context context = null; ArrayList items; public WidgetViewsFactory(Context context, Intent intent) { this.context = context; Cursor c = Items.get(context, where); items = Items.getFromCursor(c); } @Override public void onCreate() { /* */ } @Override public void onDestroy() { } @Override public int getCount() { if(items != null) { System.out.println("Count: " + items.size()); return items.size(); } return 0; } @Override public RemoteViews getViewAt(int position) { System.out.println("getViewAt: " + position); ItemBean item = items.get(position); RemoteViews row = new RemoteViews(context.getPackageName(), R.layout.item_list); row.setTextViewText(R.id.tvListItem, item.summary); System.out.println("Widget item title: " + item.summary); return row; } @Override public RemoteViews getLoadingView() { return null; } @Override public int getViewTypeCount() { return 1; } @Override public long getItemId(int position) { return position; } @Override public boolean hasStableIds() { return false; } @Override public void onDataSetChanged() { // no-op } }

布局:

我的4个项目肯定没有文本加载,我不知道它来自哪里。

有人能指出你做错了什么吗?

谢谢

这个答案帮助了我https://stackoverflow.com/a/23122006/2051381

我必须从我的remoteViewsFactory类的方法getViewTypeCount()返回1而不是0

我不得不删除

android:minHeight="?attr/dropdownListPreferredItemHeight"

从列表项的布局来使这项工作

检查您是否使用不受支持的视图。

就我而言,我在我的布局中使用View作为分隔符。 并没有意识到它不是受支持的观点之一 。

我刚删除它,小部件按预期运行。

我也来这里说:我将列表项的背景设置为

?attr/selectableitembackground

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值