继续获取这些错误信息"对于类型AppWidgetProvider"未定义onCreate(Bundle)方法。

时间:2012-02-12 08:57:19

标签: android android-widget

  

对于AppWidgetProvider类型

,未定义onCreate(Bundle)方法
public class SupermarioActivity<imageButton1> extends AppWidgetProvider {
public static SupermarioActivity Widget = null;
public static Context context;
public static AppWidgetManager appWidgetManager;
public static int appWidgetIds[];   

@Override
public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )    {     
    if (null == context) context = SupermarioActivity.context;
    if (null == appWidgetManager) appWidgetManager = SupermarioActivity.appWidgetManager;
    if (null == appWidgetIds) appWidgetIds = SupermarioActivity.appWidgetIds;

    SupermarioActivity.Widget = this;
    SupermarioActivity.context = context;
    SupermarioActivity.appWidgetManager = appWidgetManager;
    SupermarioActivity.appWidgetIds = appWidgetIds;

    Log.i("PXR", "onUpdate");


    }

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
        int appWidgetId) {


    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
    remoteViews.setImageViewResource(R.id.imageButton1, appWidgetId);


    // Tell the widget manager
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}

  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    

    imageButton1 imagebutton1 = (imageButton1) findViewById(R.id.imageButton1);

    imageButton1.setOnClickListener(new OnClickListener()
    {
      public void onClick(View v)
      {
         ImageView iv = (ImageView) findViewById(R.id.imageview1);
         iv.setVisibility(View.VISIBLE);
      }
    });
}

    private void setContentView(int main) {
    // TODO Auto-generated method stub

}
    private imageButton1 findViewById(int imagebutton1) {
    // TODO Auto-generated method stub
    return null;
}

}

3 个答案:

答案 0 :(得分:2)

您为onCreate(Bundle)定义了SupermarioActivity<imageButton1>方法,该方法看起来像属于Activity子类。但是SupermarioActivity扩展了AppWidgetProvider,而不是Activity(或任何Activity子类。)

答案 1 :(得分:1)

我认为这很简单:课程AppWidgetProvider似乎没有方法onCreate(Bundle)

  

帮助实现AppWidget提供程序的便捷类。   你可以用AppWidgetProvider做的一切,你可以做一个   常规的BroadcastReceiver。 AppWidgetProvider只是解析   收到的意图中的相关字段   onReceive(Context,Intent),并使用收到的方法调用钩子方法   附加功能。

(emph mine,from http://developer.android.com/reference/android/appwidget/AppWidgetProvider.html

如果我是回形针,我可能会张贴:

看起来你正试图制作Activity?你想:
- 扩展活动类?

答案 2 :(得分:0)

只需在您的课程中添加扩展活动