指定数据在运行时四维数组 [英] Assign data to a four Dimensional Array at RunTime

查看:160
本文介绍了指定数据在运行时四维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个四维数组,我有一个静态值的集合。但我的问题是,我想获取来自API的一些数据并把它放到四维阵列的运行时。我不知道如何做到这一点。任何丝毫的想法将是AP preciated。下面是我的示例,显示我的我的四个维数组的静态清晰度。

 静态最后弦乐listdesc [] [] [] [] =
{
    { // 灰色
      { // 浅灰
        {灰色,只有灰色},
        {浅灰,#D3D3D3},
        {dimgrey,#696969}
      },
      { // 深灰色
        {灰色,darkgrey},
        {SGI灰色92,#EAEAEA}
      }
    },
    { // 蓝色
      { // 淡蓝色
        {蓝,lightblue},
        {宝蓝2,#1C86EE}
      },
      { // 深蓝
        {蓝,darkblue},
        {钢青2,#5CACEE},
        {浅灰蓝,#B0E0E6}
      }
    },
    {//黄色
      {//浅黄
        {黄,浅黄},
        {黄色1,#FFFF00},
        {金1,#FFD700}
      },
      {// darkyellow
        {黄,darkyellow},
        {深金黄1,#FFB90F}
      }
    },
    {//红
      { // 红灯
        {红,lightred},
        {印地安1,#FF6A6A}
      },
      { // 深红
        {红,darkred},
        {耐火砖1,#FF3030},
        {栗色,#800000}
      },    }
};


解决方案

取在的AsyncTask 数据/背景和 postExecute 做到这一点。

  listdesc [] [] [] [];
的for(int i = 0; I< listdesc.length;我++){
    对于(INT J = 0; J< listdesc [I]。长度; J ++){
        对于(INT K = 0; K< listdesc [I] [J]。长度; k ++){
            对于(INT M = 0; M< listdesc [I] [J] [K]。长度; M +){
                //使用值填充
            }
        }
    }
}

I have a four dimensional array for which I have a static set of values. But my problem is I want to fetch some data from api and have to put it into the four dimensional array during runtime. I am not sure how to do this. Any slightest idea will be appreciated. Here is my sample which shows my static definition of my four dimensional array.

static final String listdesc[][][][] =
{
    { // grey
      {  // lightgray
        { "grey", "grey only" },
        { "lightgrey","#D3D3D3" },
        { "dimgrey","#696969" }
      },
      {  // darkgray
        { "grey", "darkgrey" },
        { "sgi grey 92","#EAEAEA" }
      }
    },
    { // blue
      {  // lightblue
        { "blue", "lightblue" },
        { "dodgerblue 2","#1C86EE" }
      },
      {  // darkblue
        { "blue", "darkblue" },
        { "steelblue 2","#5CACEE" },
        { "powderblue","#B0E0E6" }
      }
    },
    { // yellow
      {  // lightyellow
        { "yellow", "lightyellow" },
        { "yellow 1","#FFFF00" },
        { "gold 1","#FFD700" }
      },
      {  // darkyellow
        { "yellow", "darkyellow" },
        { "darkgoldenrod 1","#FFB90F" }
      }
    },
    { // red
      {  // lightred
        { "red", "lightred" },
        { "indianred 1","#FF6A6A" }
      },
      {  // darkred
        { "red", "darkred" },
        { "firebrick 1","#FF3030" },
        { "maroon","#800000" }
      },

    }
};

解决方案

Fetch data in AsyncTask/background and assign it in postExecute do this.

listdesc[][][][];
for (int i=0; i<listdesc.length; i++) {
    for (int j=0; j<listdesc[i].length; j++) {
        for (int k=0; k<listdesc[i][j].length; k++) {
            for (int m=0; m<listdesc[i][j][k].length; m++) {
                // populate with values
            }
        }
    }
}

这篇关于指定数据在运行时四维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆