在ImageView上使用setBackgroundDrawable方法時,Eclipse提供了以下錯誤: 「類型View中的方法setBackgroundDrawable(Drawable)不適用於參數(int)」 My ImageView的是XML定義爲:在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);
}
}
任何人有任何想法,爲什麼它給這個錯誤,或者如何解決呢?
@JoelFernandes,你有什麼編輯,我沒有得到它? –
每當您在回答或評論中使用代碼時,請用代碼標記附上代碼,以便代碼顯示格式。這就是我編輯的。 – JoelFernandes
哦,謝謝你的回答。 :) –