Eclipse marks findViewById (int) as undefined; it did the same for getResources (), but I managed to get around this by calling context.getResources () instead (as shown below) and cannot find a similar workaround for findViewById. Here is the code:
package com.myapp.android.MyWidget; import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.ComponentName; import android.content.pm.PackageManager; import android.content.res.Resources; import android.util.Log; import android.view.View; import android.widget.RemoteViews; import android.widget.Button; import android.os.Bundle; public class MyWidget extends AppWidgetProvider { private static String[] states; @Override public void onEnabled(Context context) { final Button button = (Button) findViewById(R.id.widget_state_button); states = context.getResources().getStringArray(R.array.states); }
Is there any other package I need to import for findViewById? Thanks in advance.
source share