我正在使用多維ArrayLists。 我正在讀取具有3行ID,日期和信息的Excel文件中的數據。 我設法設置arrayList,但在每個索引 即3列數據,即數組(1)id1 date1 info1。無法單獨調用info1。 我需要創建一個multy。 arraylist在那裏我可以打電話給arrayindex(1)項目info1。將EXCEL數據添加到多維ArrayList
public class MainActivity extends AppCompatActivity {
String xx;
String show;
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void order(View v) {
try {
AssetManager am=getAssets();
InputStream is=am.open("test.xls");
Workbook wb =Workbook.getWorkbook(is);
Sheet s=wb.getSheet(0);
int row =s.getRows();
int col=s.getColumns();
xx="";
for(int i=0; i<row ; i++)
{
for (int c=0; c<col; c++)
{
Cell z=s.getCell(c,i);
xx=xx+z.getContents();
xx=xx+" ";
mainArray();
}
xx=xx+"\n";
}
display(xx);
}
catch (Exception e)
{
}
}
public void display(String value)
{
TextView x=(TextView) findViewById(R.id.display);
x.setText(value);
}
public void mainArray() {
ArrayList arrayList = new ArrayList();
arrayList.add(xx);
Log.d("log1","Size of al after additions: " + arrayList.size());
Log.d("log1","Contents of al: " + arrayList);
}
}
如何啓動一個多維數組列表(ID,日期,資訊),以及如何在迭代我可以根據行/線,數據在正確的名單追加。
ArrayList
[
list_Id {id1, id2,id3,.............}
list_Date {date1, date2,date3.......}
list_Info {info1, info2, info3.......}
]
您不應該使用id,date,info as seperate Lists。你應該使用一個List來存儲行的三維值 – Jens