Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate an ImageView [duplicate]

I am designing (trying to learn) a simple widget for Android. I have:

public class NewAppWidget extends AppWidgetProvider {

Inside that class, I have the simple code:

public double angle(Calendar calendarDate) {
        //Earth rotation;
        int day = calendarDate.get(Calendar.DAY_OF_YEAR);
        int angle;
        angle = (day / 365) * 360;
        return angle;
    }

I then want to select an image and rotate it by that angle in ImageView, which totally does not work ...

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



 // Construct the RemoteViews object

 ImageView image = (ImageView) findViewById(R.layout.new_app_widget);

    image.setImageResource(R.drawable.moon10);
    image.setRotation(angle);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, new_app_widget);

}

There are probably several mistakes in there - I am a beginner.

The three errors highlighted by Android studio are:

  1. findViewById in red (cannot resolve method)
  2. angle in red (cannot resolve symbol angle)
  3. new_app_widget in last line in red (cannot resolve symbol)

Thanks for your help and have a good day.

JY

like image 600
Jean-Yves Avatar asked Sep 20 '25 18:09

Jean-Yves


1 Answers

  1. as the method is static, you will need to create view to findviewbyid(); or make void non-static
  2. angle in rotation must be int, not double
like image 176
theMatus Avatar answered Sep 22 '25 09:09

theMatus