0
A
回答
1
您可以通過使用反射在java中完成此操作。
如果你不熟悉它已經,這裏是一個很好的起點在programmcreek.com:
http://www.programcreek.com/2013/09/java-reflection-tutorial/
簡單地說,作爲一個例子,您可以使用此示例代碼通過R中遍歷您的代碼:
import java.lang.reflect.Field;
import android.util.Log;
public class ResourceUtil {
/**
* Finds the resource ID for the current application's resources.
* @param Rclass Resource class to find resource in.
* Example: R.string.class, R.layout.class, R.drawable.class
* @param name Name of the resource to search for.
* @return The id of the resource or -1 if not found.
*/
public static int getResourceByName(Class<?> Rclass, String name) {
int id = -1;
try {
if (Rclass != null) {
final Field field = Rclass.getField(name);
if (field != null)
id = field.getInt(null);
}
} catch (final Exception e) {
Log.e("GET_RESOURCE_BY_NAME: ", e.toString());
e.printStackTrace();
}
return id;
}
另外,您可以參考這個問題的更深入的瞭解: Android: Programatically iterate through Resource ids
0
進口
Field class
import java.lang.reflect.Field;
寫在你的代碼
Field[] ID_Fields = R.drawable.class.getFields(); int[] resourcesArray= new int[ID_Fields.length]; for(int i = 0; i < ID_Fields.length; i++) { try { resourcesArray[i] = ID_Fields[i].getInt(null); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
resourcesArray
內容的所有資源文件。
相關問題
- 1. 以編程方式從相機文件夾獲取圖像
- 2. 以編程方式從MP4中獲取不重疊的圖像
- 3. 以編程方式獲取AjaxControlToolkit.TabPanel中的所有控件
- 4. 以編程方式從圖像中提取文本
- 5. 以編程方式從圖像中讀取文本
- 6. 通過編程以swift方式獲取圖像文件類型
- 7. 以編程方式從Crystal Reports .rpt文件中獲取報表
- 8. 如何以編程方式獲取WooCommerce中的所有產品?
- 9. 以編程方式獲取DNN中的所有朋友
- 10. 以編程方式安卓WiFi連接
- 11. 以編程方式從MySQL獲取圖像的URL
- 12. 從uiwebview中以編程方式獲取所選元素?
- 13. 安卓捕獲圖像的文件名
- 14. 如何以編程方式從Office文件中提取和操作圖像?
- 15. 無法從安卓的Picasa圖像的選取器ACTION_GET_CONTENT中獲取圖像
- 16. iPhone:從「文檔」文件夾以編程方式設置圖像
- 17. 以編程方式確定包中圖像文件的尺寸
- 18. Android:以編程方式從WebView中的圖像庫獲取IMG SRC
- 19. Xamarin安卓從圖庫中獲取圖像數據
- 20. 如何以.jpg文件格式從圖庫中獲取圖像?
- 21. 以編程方式從安卓的藍牙打印
- 22. 以編程方式從BitBucket的「Downloads」部分獲取文件。
- 23. 如何以編程方式獲取Eclipse中常用的圖像插件
- 24. 獲取安卓手機中的所有應用程序
- 25. 以編程方式從C#中的MPEG文件中獲取快照#
- 26. 從安卓相機的NV21格式中提取黑白圖像
- 27. 以編程方式將所有髒文件保存在MatLab中
- 28. 如何以編程方式從Windows Phone媒體庫中獲取特定圖像?
- 29. 從URL中獲取所有圖像
- 30. 以編程方式從GitHub獲取
嘿傢伙感謝這些我會盡快嘗試他們,我會馬上回到你身邊! –