我可以让小部件(和按钮)出现,但我无法触发.我已经看到了几个显示这种不同方式的例子,但我无法让它发挥作用.我很长时间没有感觉到这种无助的编码,我开始感到愚蠢.
这是我到目前为止:
public class simpleclick extends appwidgetprovider { /** Called when the activity is first created. */ @OverrIDe public voID onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIDs) { final int N = appWidgetIDs.length; Toast.makeText(context,"doing on update",Toast.LENGTH_SHORT).show(); for (int i=0; i<N; i++) { int appWidgetID = appWidgetIDs[i]; Intent intent = new Intent(context,simpleclick.class); intent.setAction("ham"); PendingIntent pendingIntent = PendingIntent.getActivity(context,intent,0); RemoteVIEws vIEws = new RemoteVIEws(context.getPackagename(),R.layout.main); vIEws.setonClickPendingIntent(R.ID.Timm,pendingIntent); appWidgetManager.updateAppWidget(appWidgetID,vIEws); } } //@OverrIDe public voID onReceive(Context context,Intent intent) { // Todo auto-generated method stub Toast.makeText(context,"action is: " + intent.getAction(),Toast.LENGTH_SHORT).show(); super.onReceive(context,intent); }}
我的清单:
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.tblabs.simpleclick" androID:versionCode="1" androID:versionname="1.0"> <application androID:icon="@drawable/icon" androID:label="@string/app_name"> <receiver androID:name="simpleclick"> <intent-filter> <action androID:name="androID.appWidget.action.APPWidget_UPDATE" /> </intent-filter> <Meta-data androID:name="androID.appWidget.provIDer" androID:resource="@xml/simpleclick" /> </receiver> </application> <uses-sdk androID:minSdkVersion="5" /></manifest>
我将不胜感激!
谢谢,
温迪
示例代码:
protected PendingIntent getPendingSelfIntent(Context context,String action) { Intent intent = new Intent(context,getClass()); intent.setAction(action); return PendingIntent.getbroadcast(context,0);}vIEws.setonClickPendingIntent(R.ID.Timm,getPendingSelfIntent(context,"ham"));总结
以上是内存溢出为你收集整理的请帮助非常简单的Android小部件按钮单击.变得非常沮丧. :(全部内容,希望文章能够帮你解决请帮助非常简单的Android小部件按钮单击.变得非常沮丧. :(所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)