问题
I'm trying to set the value from my arraylist to the textview
ArrayList<Integer> arrayListPage1, arrayListPage2, arrayListPage3, arrayListPage4, arrayListPage5;
arrayListPage1 = new ArrayList<Integer>(rangeMode);
arrayListPage2 = new ArrayList<Integer>(rangeMode);
arrayListPage3 = new ArrayList<Integer>(rangeMode);
arrayListPage4 = new ArrayList<Integer>(rangeMode);
arrayListPage5 = new ArrayList<Integer>(rangeMode);
totalCardInPage = new int[totalPage+1];
for(int j=1;j<=totalPage;j++){
int x=0;
for(int i=1;i<=rangeMode;i++){
if(binaryTable[i][j]==1){
//maka i ada di page j
cardInPage[j][x]=i;
//array buat card di page 1
if (j==1){
arrayListPage1.add(i);
}else if(j==2){
arrayListPage2.add(i);
}else if(j==3){
arrayListPage3.add(i);
}else if(j==4){
arrayListPage4.add(i);
}else if(j==5){
arrayListPage5.add(i);
}
x++;
}
}
System.out.println("page-"+j+" jumlah kartu:"+x);
totalCardInPage[j]=x;
}
System.out.println("List page 1 "+arrayListPage1);
System.out.println("List page 2 "+arrayListPage2);
System.out.println("List page 3 "+arrayListPage3);
System.out.println("List page 4 "+arrayListPage4);
System.out.println("List page 5 "+arrayListPage5);
TextView text1 = (TextView) findViewById(R.id.text1);
if (arrayListPage1[0]!=null){
text1.setText(arrayListPage1[0]);
}
else{
text1.setVisibility(View.GONE);
}
if (arrayListPage1[1]!=null){
text1.setText(arrayListPage1[1]);
}
else{
text1.setVisibility(View.GONE);
}
but I got an error when I'm trying to set the arraylist value to my textview. The error said because I'm using arraylist so I cannot assign the value to the textview
anyone know how to fix this?
thanks
回答1:
It happens because You set Integer value to Your TextView and TextView finds String from resources. Convert Your Integer value to String.
For example:
text1.setText(arrayListPage1.get(0).toString());
or simple:
text1.setText(arrayListPage1.get(0) + "");
来源:https://stackoverflow.com/questions/23216577/assign-arraylist-value-to-textview