java android getResources()。getIdentifier()
問題似乎是您要轉(zhuǎn)換drawerSelection為小寫字母。在R.java文件中很明顯,標(biāo)識符的大小寫得以保留。嘗試致電:
int panelId = this.getResources().getIdentifier(drawerSelection,'id',getActivity().getPackageName());解決方法
如何從R.獲取ID的int id值?當(dāng)我使用getIdentifier它的正好回報0。
int i = getArguments().getInt(SELECTION_NUMBER); String drawerSelection = getResources().getStringArray(R.array.drawerSelection_array)[i];int panelId = this.getResources().getIdentifier(drawerSelection.toLowerCase(),'id',getActivity().getPackageName());
編輯
Xml
<LinearLayout xmlns:android='http://schemas.android.com/apk/res/android'android:layout_width='match_parent'android:layout_height='match_parent'android:orientation='vertical' ><ListView android: android:layout_width='match_parent' android:layout_height='wrap_content' ></ListView></LinearLayout>
日志
06-10 21:24:30.372: I/System.out(3572): Selection = Bus_Schedules06-10 21:24:30.372: I/System.out(3572): panelId = 0
R.java
public static final class id { public static final int Bus_Schedules=0x7f090004; public static final int basemenu=0x7f090005; public static final int content_frame=0x7f090001; public static final int drawer_layout=0x7f090000; public static final int left_drawer=0x7f090002;
相關(guān)文章:
1. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題2. 冒昧問一下,我這php代碼哪里出錯了???3. php - 淘寶訂單拆單表設(shè)計4. 如何用筆記本上的apache做微信開發(fā)的服務(wù)器5. mysql優(yōu)化 - MySQL如何為配置表建立索引?6. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)7. windows誤人子弟啊8. 實(shí)現(xiàn)bing搜索工具urlAPI提交9. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實(shí)在是找不到哪里的問題了。10. 我在網(wǎng)址中輸入localhost/abc.php顯示的是not found是為什么呢?
