2011-01-22 6 views
8

getIdentifierがクラス変数で動作するのに問題があります。これが動作するためには、奇妙だ:android/java getIdentifier with

public Drawable getStationIcon(Context context) { 
    int resId = context.getResources().getIdentifier("m1m2_16", "drawable", "com.mypackage.namehere"); 
    Drawable drawable = context.getResources().getDrawable(resId); 
    return drawable; 
} 

をしかし、これはしていません:

public Drawable getStationIcon(Context context) { 
    int resId = context.getResources().getIdentifier(this.stationIcon, "drawable", "com.mypackage.namehere"); 
    Drawable drawable = context.getResources().getDrawable(resId); 
    return drawable; 
} 

をとNORこの処理を行います。

public Drawable getStationIcon(Context context) { 
    String stationI = this.stationIcon; 
    int resId = context.getResources().getIdentifier(stationI, "drawable", "com.mypackage.namehere"); 
    Drawable drawable = context.getResources().getDrawable(resId); 
    return drawable; 
} 

そして​​は間違いm1m2_16に等しいです。私は他の選択肢、すなわち""+this.stationIconを使って試しましたが、最初のパラメータが変数のときは何も動作しません。私は行方不明のものがありますか?

+0

私は '' Log.d(TAG、 "stationIcon =" + this.stationIcon)をログに記録することをお勧めそれが実際に "m1m2_16"であることを確認するために使用の直前に 'this.stationIcon'を置きます。 –

+0

私はそうしました。それは間違いなくm1m2_16です – Ashley

答えて