2014-04-22 2 views
1

내가 문제가이 각 값을 보여 루핑 는 ArrayList의 각 텍스트 뷰 안드로이드

totalCardPerPage = 30; 
    cardNumber = 1; 
    //looping to determine textView id in my xml 
    for(int x=1;x<=totalCardPerPage;x++){ 
     //textView id 
     textId = "text"+cardNumber; 
     int id = getResources().getIdentifier(textId, "id", "com.example.radioexample"); 
     TextView currcell = (TextView) findViewById(id); 
     //get array size 
     int arrayListSize = arrayListPage1.size(); 

     //looping to show each value in textView 
     for(int y=0; y<=arrayListSize; y++){ 
      currcell.setText(arrayListPage1.get(y).toString); 
      currcell.setBackgroundColor(Color.RED); 
     } 
     cardNumber++; 
    } 

텍스트 뷰

을 수동으로 작성 또는 고정 각 텍스트 뷰에 내 ArrayList의 각 값을 표시하기 위해 노력하고있어 각각의 값을 표시 textView. 내 배열의 모든 값은 하나의 텍스트 뷰에 모여,이 코드

내가 ArrayList를 루핑을 위해 그것을 실현을 실행할 때

나는 오류를 가지고에만

5 값이있는 경우 그것이 있어야 내 배열, 각 값은 각 textView에 표시됩니다. 예를 들어

,

arraylist {a,b,c,d,e}; 
text1.setText(a); 
text2.setText(b); 
text3.setText(c); 
text4.setText(d); 
text5.setText(e); 

사람이 그것을 어떻게 알아?

감사

+0

동적으로 만들고 textviews 상위 레이아웃으로 –

+0

@jitainsharma이 경우 수동으로 작성하거나 고정 된 textView를 작성해야합니다. – user3553370

+0

할 수있는 일은 textview로만 레이아웃을 작성하고 각 for 루프에서이 레이아웃을 확장 한 다음 주 레이아웃 상위 뷰에 추가하는 것입니다. –

답변

-1

이 질문은 BUT Google 검색에서 첫 번째 결과입니다 오래되었습니다.

이 일을 위해 당신은 루프에서 ArrayList를의 모든 값을 호출하고이 코드와 같은 특별한 텍스트 뷰에 설정해야합니다

이 ArrayList를하고 textviews이있는 경우

arraylist {a,b,c,d,e}; 

TextView []tv=new TextView[5]; 
tv[0]=(TextView)findViewById(R.id.____); 
tv[1]=(TextView)findViewById(R.id.____); 
tv[2]=(TextView)findViewById(R.id.____); 
tv[3]=(TextView)findViewById(R.id.____); 
tv[4]=(TextView)findViewById(R.id.____); 

/특수 문자 뷰로로드 arraylist에 대한/루프

for(int i=0;i<arraylist.size();i++) 
       { 
        tv[i].setText(arraylist.get(i).toString()); 
       } 
관련 문제