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行问题:
<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升级后没有更新或加载所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)