2011-01-22 13 views
8

के साथ IDententifier मुझे क्लास वेरिएबल के साथ काम करने के लिए getIdentifier प्राप्त करने में समस्या हो रही है। यह अजीब बात है, क्योंकि इस काम करता है:एंड्रॉइड/जावा प्राप्त करें

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

और न ही ऐसा करता है:

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

और this.stationIcon निश्चित रूप से m1m2_16 बराबर होती है। मैंने अन्य विकल्पों की कोशिश की है, यानी ""+this.stationIcon का उपयोग करना, लेकिन पहला पैरामीटर एक चर है जब कुछ भी काम नहीं करता है। क्या मुझे कुछ याद आ रही है?

+0

मैं 'लॉग इन करने के Log.d सुझाव है (टीएजी," stationIcon = "+ this.stationIcon)' 'this.stationIcon' इसके उपयोग से ठीक पहले यह सुनिश्चित करने के लिए कि यह वास्तव में "m1m2_16" है। –

+0

मैंने ऐसा किया है, और यह निश्चित रूप से m1m2_16 है – Ashley

उत्तर

संबंधित मुद्दे