1

ImageView で setBackgroundDrawable メソッドを使用すると、Eclipse で次のエラーが発生します。

<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=" " />

Java で次のように定義および実装されます。

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);
    }
}

なぜこのエラーが発生するのか、またはそれを解決する方法を知っている人はいますか?

4

3 に答える 3

3
check1.setBackgroundDrawable(R.drawable.check);

これがエラーです。に変更してください

check1.setBackgroundResource(R.drawable.check);

また

check1.setBackgroundDrawable(getResources().getDrawable(R.drawable.check));
于 2013-12-10T17:30:32.713 に答える
0

それ以外の :-

check1.setBackgroundDrawable(R.drawable.check);

これを使って :-

check1.setImageResource(R.drawable.check);
于 2013-12-10T17:30:59.653 に答える
0

これを試して:

check1.setBackgroundDrawable(getResources().getDrawable(R.drawable.check));
于 2013-12-10T17:30:47.560 に答える