ListView in widget adds randomly items on scrolling and resizing (nested remoteviews)

前端 未结 3 1905
北恋
北恋 2020-12-17 15:52

Update: I created a repository with less code to make it a bit easier to understand.

I\'m trying to create a widget. I made it like describ

3条回答
  •  执念已碎
    2020-12-17 16:36

    I found the answer myself.

    To fix the problem with the weird adding of views on scrolling and resizing you have to call removeAllViews on the Layout where the subviews were added:

    @Override
        public RemoteViews getViewAt(int position) {
            ...
            RemoteViews itemView = new RemoteViews(context.getPackageName(), R.layout.widget_listview_item);
            itemView.removeAllViews(R.id.linearLayout_item_body);
            ...
            return itemView;
        }
    

    And the problem that the views are not displayed is because of the color: After adding

        subitem.setTextColor(R.id.textView_1, context.getResources().getColor(R.color.abc_primary_text_material_light));
        subitem.setTextColor(R.id.textView_2, context.getResources().getColor(R.color.abc_primary_text_material_light));
        subitem.setTextColor(R.id.textView_3, context.getResources().getColor(R.color.abc_primary_text_material_light));
    

    all views are displayed:

提交回复
热议问题