Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error on getDrawable

Tags:

android

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);
final 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?

like image 966
HunterX86 Avatar asked Mar 18 '26 11:03

HunterX86


1 Answers

Try this :

MyActivity.this.getResources().getDrawable(R.id.test);
like image 53
Houcine Avatar answered Mar 20 '26 01:03

Houcine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!