0

i have an imageview in my layout, and i want it to change every x second with appwidgetprovider activity. but everytime i use findViewById it gives me an error that The method findViewById(int) is undefined for the type Widget . this is my code

public class Widget extends AppWidgetProvider {
    int []imageArray={R.drawable.pic1,R.drawable.pic2,R.drawable.pic3};
    private Handler mHandler = new Handler();
    RemoteViews views;
    AppWidgetManager appWidgetManager;
    ComponentName currentWidget;
    Context context;
    TextView textview;
    DateFormat format = new SimpleDateFormat("HH:mm");

    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
        this.context = context;
        this.appWidgetManager = appWidgetManager;
        views = new RemoteViews(context.getPackageName(), R.layout.widget);
        currentWidget = new ComponentName(context, Widget.class);
        mHandler.removeCallbacks(mUpdateTask);
        mHandler.postDelayed(mUpdateTask, 100);

    }

    final Runnable mUpdateTask = new Runnable() {
        public void run() {

            Intent informationIntent = new Intent(context, MainActivity.class);
            PendingIntent infoPendingIntent = PendingIntent.getActivity(
                    context, 0, informationIntent, 0);
            views.setOnClickPendingIntent(R.id.Widget, infoPendingIntent);
            views.setTextViewText(R.id.widget_textview,
                    "" + format.format(new Date()));
            appWidgetManager.updateAppWidget(currentWidget, views);
            mHandler.postDelayed(mUpdateTask, 1000);

        }
    };

    @Override
    public void onDisabled(Context context) {
        super.onDisabled(context);
        mHandler.removeCallbacks(mUpdateTask);
    }
}
user2033624
  • 21
  • 2
  • 3

1 Answers1

0

You can use findViewById only in Activity. You may get an ImageView instance in Activity and pass it as an param to Widget.

YulCheney
  • 2,877
  • 2
  • 18
  • 14