sambob
sambob

Reputation: 93

Method undefined for type ImageView

I'm trying to create an ImageView and to set its position without XML.

I've the following code:

public class myClass {
    Activity act;
    public myClass(Activity act) {
        this.act = act;
    }

    public void setImage(){
        ImageView img = new ImageView(act);
        img.setImageResource(R.drawable.myimg);
        float xpos = 100;
        img.setX(xpos);
    }

}

I get the error:

"The method setX(float) is undefined for the type ImageView"

Upvotes: 2

Views: 762

Answers (2)

das_weezul
das_weezul

Reputation: 6122

As ImageView extends View which offers the public Method setX this should work, unless maybe you imported the wrong ImageView. Check your import statement.

Upvotes: 0

RoflcoptrException
RoflcoptrException

Reputation: 52247

This method is only available since API level 11:

http://developer.android.com/reference/android/view/View.html#setX(float)

Are you sure your coding for this API level?

Upvotes: 2

Related Questions