在这篇文章中,我们将带领您了解android–使用AppWidgetProvider在HomeWidget上显示ListView的全貌,包括android.widget.listview的相关情况。同
在这篇文章中,我们将带领您了解android – 使用AppWidgetProvider在Home Widget上显示ListView的全貌,包括android.widget.listview的相关情况。同时,我们还将为您介绍有关android app widget 中使用自定义 view、android appwidget listview没有更新、Android Appwidget textview不更新、android appwidgetprovider 与 service 交互问题的知识,以帮助您更好地理解这个主题。
本文目录一览:- android – 使用AppWidgetProvider在Home Widget上显示ListView(android.widget.listview)
- android app widget 中使用自定义 view
- android appwidget listview没有更新
- Android Appwidget textview不更新
- android appwidgetprovider 与 service 交互问题
android – 使用AppWidgetProvider在Home Widget上显示ListView(android.widget.listview)
我想创建一个包含ListView的Home Widget,但我不知道这是否可行,如果可能,该怎么做.
我使用的是ListActivity,它很简单,但无法找到使用appwidgetprovider的方法.
谢谢你的帮助
解决方法:
遗憾的是,这是不可能的,app小部件不支持ListViews.
android app widget 中使用自定义 view
app widget 开发中,我想 使用自己定义的 view, 因为 app widget 支持 RemoteViews, 我想问的是 RemoteViews 中怎么样使用自己的 view, 如自定义 view 是 com.my.AwView, 使用代码怎么样加载这个 view 呢?android appwidget listview没有更新
Intent update = new Intent(context,MenuWidgetProvider.class); update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,appWidgetIds); PendingIntent pIUpdate = PendingIntent.getbroadcast(context,update,0); ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)). set(AlarmManager.RTC,nextTime.toMillis(false),pIUpdate); Log.d(TAG,"updating: " + dmt.mealName); for (int i = 0; i < appWidgetIds.length; ++i) { int widgetId = appWidgetIds[i]; RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.widget_menu); // meal name views.setTextViewText(R.id.widget_locname,prefs.getString(PREF_WIDGET_LOCNAME,"")); // adapter Intent adapter = new Intent(context,MenuWidgetAdapterService.class); adapter.putExtra(EXTRA_LOCATIONID,prefs.getInt(PREF_WIDGET_LociD,-1)); adapter.putExtra(EXTRA_MEALNAME,dmt.mealName); adapter.putExtra(EXTRA_DATE,dmt.date.toString()); views.setRemoteAdapter(R.id.widget_list,adapter); // update manager.updateAppWidget(widgetId,views); } super.onUpdate(context,manager,appWidgetIds);
奇怪的是,当更新发生时,onUpdate()方法运行 – 我看到Log.d调用的输出 – 但我的RemoteViewsFactory中没有调用onDataSetChanged().即使我调用notifyAppWidgetViewDataChanged,也没有效果.
解决方法
我是如何解决它的:
在你的WidgetProviderClass中
adapter.setData(Uri.fromParts("content",String.valueOf(appWidgetIds[i]+randomNumber),null));
randomNumber是一个随机数(WidgetProvider类的公共静态成员).
然后在RemoteViewsFactory类中,执行:
appWidgetId = Integer.valueOf(intent.getData().getSchemeSpecificPart()) - WidgetProvider.randomNumber;
这让“服务”认为它必须为另一个小部件创建一个Factory,因此创建一个带有更新值的新工厂,该工厂附加到您的小部件.
希望这可以帮助.
Android Appwidget textview不更新
但是在onRecive方法中,当我尝试使用RemoteViews为我的组件设置文本时,文本不会更新,也不会调用任何错误.我在下面附上了我的代码,任何帮助都会很棒.
谢谢,
中号
package com.android.FirstWidget;import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.appwidgetprovider; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageButton; import android.widget.RemoteViews; public class Exampleappwidgetprovider extends appwidgetprovider { @Override public void onReceive(Context context,Intent intent) { // Todo Auto-generated method stub Log.e("ds",intent.getAction()); Log.e("f","f"); if(intent.getAction().contains("1")){ RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.wid); views.setTextViewText(R.id.textView1,"heyheyhey"); Log.e("fssss","sssf"); } super.onReceive(context,intent); } public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; // Create an Intent to launch ExampleActivity Intent intent = new Intent(context,Exampleappwidgetprovider.class); intent.setAction("1"); PendingIntent pendingIntent = PendingIntent.getbroadcast(context,intent,0); // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.wid); views.setonClickPendingIntent(R.id.arrowLeft,pendingIntent); views.setonClickPendingIntent(R.id.arrowRight,pendingIntent); //views.set // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId,views); } } }
解决方法
package com.android.FirstWidget;import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.appwidgetprovider; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageButton; import android.widget.RemoteViews; public class Exampleappwidgetprovider extends appwidgetprovider { @Override public void onReceive(Context context,Intent intent) { // Todo Auto-generated method stub Log.e("ds",intent.getAction()); Log.e("f","f"); RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.wid); if(intent.getAction().contains("arrow_left")){ views.setTextViewText(R.id.textView1,"left"); Log.e("fssss","sssf"); } else if(intent.getAction().contains("arrow_right")){ views.setTextViewText(R.id.textView1,"right"); Log.e("fssss","sssf"); } else { super.onReceive(context,intent); } ComponentName componentName = new ComponentName(context,Exampleappwidgetprovider.class); AppWidgetManager.getInstance(context).updateAppWidget(componentName,views); } public void onUpdate(Context context,Exampleappwidgetprovider.class); intent.setAction("arrow_left"); PendingIntent pendingIntent = PendingIntent.getbroadcast(context,pendingIntent); intent = new Intent(context,Exampleappwidgetprovider.class); intent.setAction("arrow_right"); pendingIntent = PendingIntent.getbroadcast(context,views.setonClickPendingIntent(R.id.arrowRight,views); } } }
此外,虽然我相信你编码的内容应该可以工作,但如果没有,你可以尝试在清单文件中设置按钮的intent操作.它应该是这样的
<intent-filter > <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> <action android:name="com.android.FirstWidget.arrow_left"/> <action android:name="com.android.FirstWidget.arrow_right"/> </intent-filter>
我想现在应该可以了.我自己偶然发现了这个问题,并在此找到了解决方案:Clickable widgets in android
android appwidgetprovider 与 service 交互问题
功能描述 :在手机桌面上开发一个时钟widget,每隔一秒刷新一下时间 。
问题描述:想在service中用timer+timertask 控制时钟 ,在appwidgetprovider 中使用这个service 。
我试过的方法 :1.使用startService()方法 , 发现屏幕上的widget不会跳动 。
2使用过bindService方法,但是运行出现错误,不知道是不是widget组件不支持bindservice 。
我已经增删改查四天了,希望有好心的高手能帮我解决这个问题 。
希望能按照我的问题描述 , 给出详细的关键代码 :appwidgetprovider 中如何调用service , service中timer怎么编写,求解答。。。。
如果觉得我说的不明白,可以给我发邮件:CZhaoSCU@gmail.com ,详细交流 。真的十分感谢。
今天关于android – 使用AppWidgetProvider在Home Widget上显示ListView和android.widget.listview的分享就到这里,希望大家有所收获,若想了解更多关于android app widget 中使用自定义 view、android appwidget listview没有更新、Android Appwidget textview不更新、android appwidgetprovider 与 service 交互问题等相关知识,可以在本站进行查询。
本文标签: