2011-11-22 6 views
0

내 목록보기에 TextView를 추가하려고하지만 강제로 닫으면 강제 종료됩니다. 노래 앞에 노래 이름에 주먹 글자를 표시하려고합니다. songlist는 문자열 arraylist이며 이것은 모두 목록보기에 있습니다.TextView를 디바이더로 ListView에 추가

Collections.sort(songtitle); 
       TextView divide = (TextView)findViewById(R.layout.song); 

       adapter = new ArrayAdapter<String>(this,R.layout.song,songtitle); 
       int l= 0; 
       while(l < adapter.getCount()-1){ 
        if(songtitle.get(l).charAt(0) == songtitle.get(l+1).charAt(0)){ 
         adapter.add(songtitle.get(l)); 
        }else{ 
         String songname1 = songtitle.get(l); 
         String newString = songname1.substring(0,1); 
         divide.append(newString);// This is where i get the force close ... I want to display this textView //// 

        } 
       l++; 
       } 


       setListAdapter(adapter); 

     } 
+0

공유 errorLog. 또한 songtitle arrayList. –

답변

1

사용자 지정보기와 함께 CustomAdapter를 사용해야합니다.

+0

+1, 존경합니다.하지만이 1 줄의 답과 함께 더 많은 정보를 제공해야합니다. –

+0

나는 정확한 대답을 위해 –

3

앞에서 설명한대로 사용자 정의 Adapter을 만들어야합니다. 이에

public class MyAdapter extends BaseAdapter 

getView()getViewTypeCount() 특히 오버라이드 (override) 할 필요가 몇 가지 방법이 있습니다. 후자는 List (예 : 노래 및 문자 TextView)에있을 수있는 ListItem의 유형 수를 반환합니다.

ListView에 분리자를 추가하는 경우 this guide을 확인해야합니다.

+0

+1을 설명 할 수있는 방법을 잘 모르겠습니다. –