To start off, an image says thousand words:
This takes place although getViewAt is called 4 items as my cursor size is.
Here's the code:
public class WidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
System.out.println("Factory");
return(new WidgetViewsFactory(this.getApplicationContext(), intent));
}
}
The widget provider:
public class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory, LNTConstants
{
private Context context = null;
ArrayList<DBItemModel> 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
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/tvListItem"
style="@style/text_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?attr/dropdownListPreferredItemHeight" />
</RelativeLayout>
My 4 items definitely don't have the text loading and i don't know where that is coming from.
Could someone point out what am doing wrong?
Thanks
Check if you are using a non-supported view.
In my case, I was using View
in my layout as a divider. and didn't realize it's not one of the supported views.
I just removed it and the widget behaved as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With