android - getDrawable 错误

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

我在“getDrawable”上遇到错误

getDrawable(R.drawable.test);

它说:对于 new View.OnClickListener(){} 类型,方法 getDrawable(int) 未定义。

如何解决?

最佳答案

试试这个:

MyActivity.this.getResources().getDrawable(R.id.test);

关于android - getDrawable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6074805/

相关文章:

android - Activity 恢复时不会调用 onSurfaceCreated()

广播 PACKAGE_REMOVED/PACKAGE_ADDED 的 Android 权限

android - 当 View 在 FlatList 中时, View borderRadius 样式不适用于 Android

java - 使用java代码隐藏ActionBarActivity中的标题栏

android - 如何在Android中制作IDE,如AIDE,在Android手机本身编译android项目

java - Android MediaCodec 如何创建解码器?

android - 如何将jpg图片保存到sd卡中自己的目录

android - admob如何检测位置

android - styles.xml 中 com.google.ads 命名空间的属性/标签

android - 如何检查 IntentService 是否已启动