I am straggling with multidimensional ArrayLists. I'm reading data from a excel file with 3 rows ID, Date, and INFO. I managed to set the arrayList but with the 3rows data in each index i.e array (1) id1 date1 info1. Can not call info1 individually. I need to create a multy. arraylist where I can call arrayindex(1) item info1.
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);
}
}
How to initiate a multidimensional arraylist(id, date, info) and how on iteration I can append depending on row/line, the data in the proper list.
ArrayList [ list_Id {id1, id2,id3,.............} list_Date {date1, date2,date3.......} list_Info {info1, info2, info3.......} ]
Aucun commentaire:
Enregistrer un commentaire