AbdulRehman
AbdulRehman

Reputation: 67

Eclipse error while using setBackgroundDrawable on an ImageView

When using the setBackgroundDrawable method on an ImageView, Eclipse gives the following error: "The method setBackgroundDrawable(Drawable) in the type View is not applicable for the arguments (int)" My ImageView is defined in xml as:

<ImageView
                android:id="@+id/ivCheck1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/box"
                android:contentDescription=" " />

Defined and implemented in java as:

public class QuizList extends Activity implements View.OnClickListener {

ImageView check1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.theView);
    IntializeVariables();
    IntializeChecks()
}

private void IntializeVariables() {
    // TODO Auto-generated method stub

    check1 = (ImageView) findViewById(R.id.ivCheck1);

}

private void IntializeChecks() {
    // TODO Auto-generated method stub
    boolean check = getPrefs.getBoolean("quiz1pref", false);
    if (check == true) {
        check1.setBackgroundDrawable(R.drawable.check);
    }
}

Anyone got any idea why it's giving this error, or how to solve it?

Upvotes: 1

Views: 1050

Answers (3)

amit singh
amit singh

Reputation: 1422

Instead of :-

check1.setBackgroundDrawable(R.drawable.check);

Use this :-

check1.setImageResource(R.drawable.check);

Upvotes: 0

Joel Fernandes
Joel Fernandes

Reputation: 4856

Try this:

check1.setBackgroundDrawable(getResources().getDrawable(R.drawable.check));

Upvotes: 0

Nam Vu
Nam Vu

Reputation: 5725

check1.setBackgroundDrawable(R.drawable.check);

This is the error. Please change it to

check1.setBackgroundResource(R.drawable.check);

or

check1.setBackgroundDrawable(getResources().getDrawable(R.drawable.check));

Upvotes: 3

Related Questions