error on getDrawable
private int ServiceLeft;
private int ServiceRight;
private int Services;
final TextView countTextViewPlusL = (TextView) findViewById(R.id.TextViewCountL);
final Button ServiceButtonLeft = (Button) findViewById(R.id.ButtonServiceLeft);
final TextView countTextViewPlusR = (TextView) findViewById(R.id.TextViewCountR);
f开发者_如何转开发inal Button ServiceButtonRight = (Button) findViewById(R.id.ButtonServiceRight);
View.OnClickListener listner = new View.OnClickListener() {
public void onClick(View v) {
switch(v.getId()) {
case R.id.ButtonServiceRight:
ServiceRight++;
break;
case R.id.ButtonServiceLeft:
ServiceLeft++;
break;
}
if(Services % 2 == 0) {
getDrawable(R.drawable.test);
}
}
};
i get an error on "getDrawable"
getDrawable(R.drawable.test);
it says: The method getDrawable(int) is undefined for the type new View.OnClickListener(){}.
how to solve this?
Try this :
MyActivity.this.getResources().getDrawable(R.id.test);
It is a scope problem.
Assume your class wherein all this code is located has the signature:
public class MyAct extends Activity
Then you must call
MyAct.this.getDrawable (R.drawable.test);
while inside the OnClickListener.
Call it throug YourActivityName.this.getDrawable(R.drawable.test);
精彩评论