findViewById undefined

Posted by areyling on Stack Overflow See other posts from Stack Overflow or by areyling
Published on 2010-05-24T10:33:44Z Indexed on 2010/05/24 10:41 UTC
Read the original article Hit count: 792

Filed under:
|
|

Eclipse is marking findViewById(int) as undefined; it was doing the same thing for getResources(), but I was able to get around that by calling context.getResources() instead (as seen below) and can't seem to 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 another package I need to import for findViewById? Thanks in advance.

© Stack Overflow or respective owner

Related posts about android

Related posts about beginner