java android getResources()。getIdentifier()
問題似乎是您要轉換drawerSelection為小寫字母。在R.java文件中很明顯,標識符的大小寫得以保留。嘗試致電:
int panelId = this.getResources().getIdentifier(drawerSelection,'id',getActivity().getPackageName());解決方法
如何從R.獲取ID的int id值?當我使用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;
相關文章:
1. 點擊頁面就自動輸入到mysql.求解2. java - IDEA從SVN檢出項目 并在tomcat上運行 求詳細流程3. node.js - nodejs使用formidable上傳文件問題4. javascript - windos下第一次用Django無法正確創建工程目錄5. node.js - 帶有node_modules目錄的項目,用phpstorm打開速度極慢,怎么解決?6. java - 多叉樹求值,程序高手,算法高手看過來7. javascript - JS用ajax爬取百度外賣店家信息8. android - 安卓做前端,PHP做后臺服務器 有什么需要注意的?9. html5 - 有人做過防微信app界面的H5 demo嗎?10. css - 請問B站頂部的模糊半透明導航條是怎么實現的呢?
