2011-01-22 12 views
8

Tengo problemas para obtener getIdentifier para trabajar con una variable de clase. Es extraño, porque esto funciona:Android/Java getIdentifier con

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

Pero esto no es así:

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

Y tampoco esto:

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; 
} 

Y this.stationIcon definitivamente es igual a m1m2_16. He intentado otras alternativas, es decir, usando ""+this.stationIcon, pero nada funciona cuando el primer parámetro es una variable. ¿Se me escapa algo?

+0

Yo sugeriría que entrar 'Log.d (TAG, "stationIcon =" + this.stationIcon)' el 'this.stationIcon' justo antes de su uso para asegurarse de que realmente es" m1m2_16 ". –

+0

Lo he hecho, y definitivamente es m1m2_16 – Ashley

Respuesta

Cuestiones relacionadas