我有一个四维数组,为此我有一组静态值。但是我的问题是我想从api获取一些数据,并且必须在运行时将其放入四维数组。我不确定该怎么做。任何细微的想法将不胜感激。这是我的示例,显示了我对四维数组的静态定义。
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" }
},
}
};
最佳答案
在AsyncTask
/ background中获取数据并在postExecute
中进行分配。
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
}
}
}
}