0

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
  • show your logcat file Commented Apr 22, 2014 at 10:14

1 Answer 1

3

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) + ""); 
Sign up to request clarification or add additional context in comments.

2 Comments

the error still said "The type of the expression must be an array type but it resolved to ArrayList<Integer>"
You need to use get() method instead. Also my previous information is correct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.