2011-09-11 3 views
0

로 채워리스트 뷰에 테마를 설정하는 방법 :단순히 이런 식으로 채워지는 목록보기가 setListAdapter

setListAdapter(new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_multiple_choice, aux)) 

'보조'는 웹 서비스를 통해 채워집니다 static String[] aux = null;의를.

정적 목록보기 요소, 파일 lista.xml에서 테스트했습니다. here을 볼 수 있습니다 (아래쪽을 보면 "목록 항목 1, 목록 항목 2"를 넣을 것입니다. 그 값을 dinamically 채울 필요가 ...)

내 질문은, 어떻게 내 listadapter에 테마를 적용 할 수 있습니까? 내가 믿는

나는 시작과 함께 :

setListAdapter (새 ArrayAdapter와 (이, R.layout.lista, AUX))

하지만이 두 가지 문제가있다.

(1) XML로 작업하고 Java (setlistadapter)에서 채우는 방법을 모른다. (2) 나는 체크 박스를 잃을 것이라고 생각한다.

그러나 누군가가 (1) 처음에 도울 수 있다면 감사드립니다 :) 나는 정말로 무엇이 지금하고 있는지 모른다.

답변

1
setListAdapter(new ArrayAdapter(this, R.layout.lista, aux)) 

시작은 맞지만 사용자 지정 ListItem 레이아웃을 원한다면 사용자 지정 ListAdapter를 작성해야합니다. 예를 들어 extend ArrayAdapter<YourItemClass>입니다. 여기서 메소드 getView()을 덮어 쓰고이 방법으로 사용자 정의 레이아웃을 Aux 객체의 값으로 채 웁니다. 당신이 당신의 목록보기 항목 ID /와

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:id="@+id/textview" android:layout_weight="1"> 

</TextView> 

에 대한 레이아웃에 ID를 설정해야 ArrayAdapter와 대한

는 텍스트 뷰 당신은 당신의 listAdapter이보기에 렌더링하는 말.

편집 : 오, 당신은 배우고 목록의 소유자 개념을 준수해야합니다. 여기에 : How to load the Listview "smoothly" in android

+0

도움을 주셔서 감사합니다. 문제가 있습니다 ... 귀하의 제안에 따라, 나는 android : id (and state)의 android : id 텍스트를 빨리 바꿔서 setListAdapter 새로운 ArrayAdapter (this, R.layout.lista, R.id.textview, aux)); 문제는 모든 listview 요소가 레이아웃의 다른 모든 요소를 ​​작성하므로 모두 엉망입니다. 이 문제를 어떻게 해결할 수 있습니까? – Tiago

+0

아마도 기본 모델 데이터가 "올인원"개체이기 때문에 Customized ListAdapter에서 getItem (int) 메서드를 정의해야합니다. 이 방법에서는 ItemObject (aux)에서 하나의 항목을 가져 오는 방법을 정의합니다. – Michele

+0

감사합니다. – Tiago

관련 문제