2012-07-21 7 views
1

:ArrayAdapter에 사용자 정의 객체 추가. 데이터를 가져 오는 방법? 이것은 내가 지금까지 무엇을 가지고

사용자 정의 개체 :

class ItemObject { 
    List<String> name; 
    List<String> total; 
    List<String> rating; 

public ItemObject(List<ItemObject> io) { 
    this.total = total; 
    this.name = name; 
    this.rating = rating; 
} 
} 

어댑터에 전화 : (가) 위의 확인을 보이는 가정

List<String> names, ratings, totals; 

ItemObject[] io= new ItemObject[3]; 
io[0] = new ItemObject(names); 
io[1] = new ItemObject(rating); 
io[2] = new ItemObject(totals); 

adapter = new ItemAdapter(Items.this, io); 
setListAdapter(adapter); 

, 내 질문은 어떻게 나는 것 생성자 인 ItemAdapter를 설정하고 세 개의 List를 객체에서 풉니 다. 그리고, 상기의 getView에서 이것들을 할당 :

각 정합 위치로 예를 들면

TextView t1 = (TextView) rowView.findViewById(R.id.itemName); 
    TextView t2 = (TextView) rowView.findViewById(R.id.itemTotal); 
    RatingBar r1 = (RatingBar) rowView.findViewById(R.id.ratingBarSmall); 

, (T1)에 배열 "이름"에 위치 0. 배열의 위치 0이 t1에 "합계"됩니다. r1에 배열 "등급"의 위치 0.

편집 : 누군가가 전체 어댑터를 쓰는 것을 원하지 않습니다. 데이터를 사용할 수 있도록 목록을 사용자 지정 개체에서 언 래핑하는 방법을 알아야합니다. (다른 질문에서 제기 한 것 또는 전혀 다른 질문이 없습니다.)

+0

이이 질문에 대단히 유사하다 그런

class ItemObject { String name; String total; String rating;// are you sure this isn't a float public ItemObject(String total, String name, String rating) { this.total = total; this.name = name; this.rating = rating; } } 

귀하의 목록은 ItemObject의 목록에 병합됩니다 어제 : [여러 목록을 ArrayAdapter에 전달] (0120-558-3898/1267661) – Sam

+0

다른 질문은 단순히 어떻게 (또는 어떤 방법으로 사용). 사실, 나는 아직도 그것을 어떻게하는지 연구하고있다. 이 질문은 그 일을하는 한 가지 특별한 방법을 언급하고 있습니다. 또한, 그 질문에서 전혀 길러지지 않는 길. 나는 이것을 처리하는 방법을 여전히 결정하고있다. 그리고 나는 아직도 제공된 답변에 도움을 주신 모든 분들께 감사드립니다. 나는 그 아이디어들 중 하나로 돌아갈 수있다. – KickingLettuce

+0

사람들에게 감사하는 일반적인 방법은 의미있는 답변을 upvote하고 올바른 답변을 표시하는 것입니다. – Sam

답변

11

코드가 실제 형식으로 작동하지 않습니다. ItemObject에 정말로 데이터 목록이 필요합니까? 내 생각 엔 아니오이고 행 레이아웃의 3 개보기에 해당하는 3 개의 문자열을 보유하는 ItemObject 만 있으면됩니다. 이 경우 :

List<String> names, ratings, totals; 
ItemObject[] io= new ItemObject[3]; 
// use a for loop 
io[0] = new ItemObject(totals.get(0), names.get(0), ratings(0)); 
io[1] = new ItemObject(totals.get(1), names.get(1), ratings(1)); 
io[2] = new ItemObject(totals.get(2), names.get(2), ratings(2)); 
adapter = new ItemAdapter(Items.this, io); 
setListAdapter(adapter); 

그리고 어댑터 클래스 :

public class ItemAdapter extends ArrayAdapter<ItemObject> { 

     public ItemAdapter(Context context, 
       ItemObject[] objects) { 
      super(context, 0, objects);   
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      // do the normal stuff 
      ItemObject obj = getItem(position); 
      // set the text obtained from obj 
        String name = obj.name; //etc  
        // ... 

     }  

} 
+1

이것은 (어떤 이유로) 닫히는 것으로 투표 되었기 때문에 나는 너무 늦기 전에 이것을 올바른 것으로 투표 할 것입니다. 당신이 신용을 얻고 싶었고 이것은 내가 찾고있는 것이 었습니다! – KickingLettuce

관련 문제