Nested Arrays in Android xml

前端 未结 1 522
心在旅途
心在旅途 2020-12-16 05:01

Previously I had a simple string-array that contained a URL it looked like

    
      http://www.goo         


        
1条回答
  •  感情败类
    2020-12-16 05:46

    This is what I've done to accomplish something like this:

    
    
        
            @array/menu_item_dashboard
            @array/menu_item_index
        
    
        
            @drawable/transparent
            Dashboard
            home
        
        
            @drawable/transparent
            Title
            index
        
    
    

    And to access:

    TypedArray menuResources = getResources().obtainTypedArray(R.array.menu_items);
    
    TypedArray itemDef;
    
    for (int i = 0; i < menuResources.length(); i++) {
        int resId = menuResources.getResourceId(i, -1);
        if (resId < 0) {
            continue;
        }
    
        itemDef = getResources().obtainTypedArray(resId);
        //itemDef.getDrawable(0)
        //itemDef.getString(1)
        //itemDef.getString(2)
    }
    

    0 讨论(0)
提交回复
热议问题