android-appwidget listview行在Marshmallow升级后没有更新或加载

android-appwidget listview行在Marshmallow升级后没有更新或加载,第1张

概述我有一个小部件应用程序,没有问题 Android Lollipop或较低的 *** 作系统.当我将nexus 5升级到Marshmallow(android 6.0)时,我意识到我的小部件在加载自定义行列表视图时遇到问题. Widget有一个动态textView和一个动态listView. textView工作得很好;但是listView行项目没有希望.当我添加小部件时,行处于加载阶段.它与Lollipo 我有一个小部件应用程序,没有问题 Android Lollipop或较低的 *** 作系统.当我将nexus 5升级到Marshmallow(androID 6.0)时,我意识到我的小部件在加载自定义行列表视图时遇到问题. Widget有一个动态textVIEw和一个动态ListVIEw. textVIEw工作得很好;但是ListVIEw行项目没有希望.当我添加小部件时,行处于加载阶段.它与Lollipop或更低版本的设备完全相同,但不适用于Marshmallow.我相信棉花糖正在引发一个我无法找到它的问题.我希望有人告诉我我做错了什么并帮助我解决这个问题.我很感激所有的帮助.谢谢.

WidgetProvIDer.class:

@OverrIDe    public voID onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIDs) {        System.out.println("WidgetProvIDer.onUpdate()");        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);        final boolean isMaviKart = MainUtils.getCardType(context).equals(Constants.CARD_TYPE_MAVI);        try {            //set Widget ID            Componentname thisWidget = new Componentname(context,WidgetProvIDer.class);            int[] allWidgetIDs = appWidgetManager.getAppWidgetIDs(thisWidget);            MainUtils.setWidgetID(prefs,allWidgetIDs[allWidgetIDs.length - 1]);            for (int i = 0; i < appWidgetIDs.length; i++) {                Intent intentService = new Intent(context,WidgetService.class);                intentService.putExtra(AppWidgetManager.EXTRA_APPWidget_ID,appWidgetIDs[i]);                intentService.setData(Uri.parse(intentService.toUri(Intent.URI_INTENT_SCHEME)));                RemoteVIEws Widget = new RemoteVIEws(context.getPackagename(),R.layout.Widget);                Widget.setRemoteAdapter(appWidgetIDs[i],R.ID.List_vIEw,intentService);                Intent clickIntent = new Intent(context,MainActivity.class);                PendingIntent clickPI = PendingIntent.getActivity(context,clickIntent,PendingIntent.FLAG_UPDATE_CURRENT);                Widget.setPendingIntentTemplate(R.ID.List_vIEw,clickPI);                if (isMaviKart) {                    Widget.setTextVIEwText(R.ID.kalanPara,String.valueOf(MainUtils.getTokenPass(prefs)));                    Widget.setTextVIEwText(R.ID.currency_tl," Geçiş");                }                else {                    Widget.setTextVIEwText(R.ID.kalanPara,String.valueOf(MainUtils.getTotalMoney(prefs)));                    Widget.setTextVIEwText(R.ID.currency_tl," TL");                }                appWidgetManager.updateAppWidget(appWidgetIDs[i],Widget);            }        }        catch (Exception e) {            e.printstacktrace();            Toast.makeText(context,context.getResources().getString(R.string.error_occured),Toast.LENGTH_SHORT).show();        }        super.onUpdate(context,appWidgetManager,appWidgetIDs);    }    @OverrIDe    public voID onReceive(Context context,Intent intent) {        super.onReceive(context,intent);        System.out.println("WidgetProvIDer.onReceive()");        String key = intent.getStringExtra(Constants.EXTRA);        if (key != null)            Log.e("TEST",key);    }

WidgetVIEwsFactory.class:

@OverrIDe    public RemoteVIEws getVIEwAt(int position) {        Intent intent = new Intent();        Bundle extras = new Bundle();        rowbutton = context.getResources().getIDentifIEr("Widget_button","ID",context.getPackagename());        rowText = context.getResources().getIDentifIEr("Widget_textvIEw",context.getPackagename());        RemoteVIEws row = new RemoteVIEws(context.getPackagename(),R.layout.row);        // set button nameS        row.setTextVIEwText(rowbutton,getFeeTypes(position));        // simple rows:        configureRowsInListvIEw(row,position,context.getResources().getcolor(R.color.DeepSkyBlue),VIEw.VISIBLE);        extras.putString(Constants.EXTRA,getEventKey(position));        intent.putExtras(extras);        row.setonClickFillinIntent(rowbutton,intent);        row.setonClickFillinIntent(rowText,intent);        return row;    }

WidgetService.class:

public class WidgetService extends RemoteVIEwsService {    @OverrIDe    public RemoteVIEwsFactory onGetVIEwFactory(Intent intent) {        return(new WidgetVIEwsFactory(this.getApplicationContext()));    }}

MainActivity.class :(关键字在Marshmallow上返回null)

@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    prefs = PreferenceManager.getDefaultSharedPreferences(this);    String keyWord = getIntent().getStringExtra(Constants.EXTRA);    if (keyWord == null) {        keyWord = "null";        Log.e("onCreate() ","No data Arrived yet!");    }} private voID updateWidgetScreen(String updateData,String currencyType) {        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);        RemoteVIEws remoteVIEws = new RemoteVIEws(getPackagename(),R.layout.Widget);        Componentname thisWidget = new Componentname(this,WidgetProvIDer.class);        remoteVIEws.setTextVIEwText(R.ID.kalanPara,updateData);        remoteVIEws.setTextVIEwText(R.ID.currency_tl,currencyType);        Intent intent = new Intent(this,WidgetService.class);        intent.putExtra(AppWidgetManager.EXTRA_APPWidget_ID,MainUtils.getWidgetID(prefs));        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));        remoteVIEws.setRemoteAdapter(MainUtils.getWidgetID(prefs),intent);        Intent clickIntent = new Intent(this,MainActivity.class);        PendingIntent clickPI = PendingIntent.getActivity(this,PendingIntent.FLAG_UPDATE_CURRENT);        remoteVIEws.setPendingIntentTemplate(R.ID.List_vIEw,clickPI);        appWidgetManager.updateAppWidget(thisWidget,remoteVIEws);        Log.e("updateWidgetScreen",updateData+" updateData - WidgetID: "+ MainUtils.getWidgetID(prefs));    }

ListVIEw行问题:

解决方法 我发现了我犯的错误.我有一个带有按钮的自定义列表视图,其中包含样式androID:style / Widget.Material.button.当我删除button的样式时,它解决了我的问题.
<button            androID:ID="@+ID/Widget_button"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_gravity="center"            androID:text="button"            androID:layout_marginRight="10dp"            androID:gravity="center"            androID:padding="8dp"            androID:textcolor="@color/White"            ****            /><style name="Materialbutton" parent="androID:style/Widget.Material.button">       <item name="androID:background">@drawable/raised_button_background</item></style>
总结

以上是内存溢出为你收集整理的android-appwidget listview行在Marshmallow升级后没有更新或加载全部内容,希望文章能够帮你解决android-appwidget listview行在Marshmallow升级后没有更新或加载所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1135629.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存