2011-10-27 5 views
0

findViewByIdに使用できる同等のコード行はありますか? Eclipseでは、AppWidgetProviderの型に対して未定義であることがわかります。findViewByIdは、AppWidgetProviderの<my class name is here>タイプでは未定義です

ボタンのクリックハンドラを設定しようとしています。

public class WidgetProvider extends AppWidgetProvider implements OnClickListener{ 

    final Button buttonOnOff = (Button) findViewById(R.id.button_on_off); 

    @Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
     int[] appWidgetIds) { 

     /* 
     * Set Click Listener 
     */ 
     buttonOnOff.setOnClickListener(this); 

     /* 
     * The following 3 lines of code are required to display the widget on the screen. 
     */ 
     RemoteViews remoteView = new RemoteViews(context.getPackageName(), 
      R.layout.appwidget_layout); 

     ComponentName myWidget = new ComponentName(context, 
      WidgetProvider.class); 
     appWidgetManager.updateAppWidget(myWidget, remoteView); 

    } 

    @Override 
    public void onClick(View v) { 
    } 
} 

答えて

1

コードは、AppWidgetsを使用しているときとは多少異なります。基本的には、従来のボタンやfindViewByIdsではなく、RemoteViewで作業する必要があります。 AppWidgetsの書き方については、related answerを参照してください。特に、developer.comチュートリアルの2つのリンク。

+0

こんにちは、ありがとうございます。本当に、Emad –

関連する問題