0

TextViews 및 Checkbox가있는 사용자 정의 ListView 용 사용자 정의 배열 어댑터를 만들었습니다. 내 customadapter에서 isChecked()라는 메서드를 만들었습니다. -adapter.getItem()은 무엇을 반환합니까?

static class personHolder 
    { 
     TextView txtName; 
     TextView txtNumber; 
     CheckBox checkbox; 
     public boolean isChecked(){ 
      boolean isChecked_boolean = false; ///this holds the return value, of whether the checkbox is checked or not. 
      if(checkbox.isChecked()){ 
       isChecked_boolean = true; 
      } 
      else{ 
       isChecked_boolean = false; 
      } 
      return isChecked_boolean; 
     } 
    } 
} 

OK. (. ((personHolder) adapter.getItem는 (i))의 IsChecked() == true)가

나는 줄에서 오류가 발생하지만
public ArrayList<PeopleDetails> checkbox_SMS(ListAdapter adapter){ 
    ArrayList<PeopleDetails> people_SMS = new ArrayList<PeopleDetails>(); 
    for(int i = 0; i < adapter.getCount(); i++){ 
     if(((personHolder) adapter.getItem(i)).isChecked() == true){ 
      people_SMS.add((PeopleDetails) people_details.toArray()[i]); 
      ///adds the corresponing people_details item to the arraylist of PeopleDetails, to send SMS messages to. 
     } 
    } 
    return people_SMS; ///returns the list. 

} 

말을하는 경우 : 난 그렇게처럼 내보기를 통해 반복을하는 루프를 사용하여 알고 PeopleDetails에서 personHolder로 캐스팅 할 수 없습니다. PeopleDetails는 TextView의 데이터에 대한 customadapter에 전달하는 유형입니다. 나는 무엇을 잘못 했는가?

질문 - 원하는 결과를 제대로 얻으려면 그 줄을 어떻게 사용해야합니까? 도와 주셔서 감사합니다!!

package com.example.partyorganiser; 

import java.util.ArrayList; 

import android.app.Activity; 
import android.content.Context; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.CheckBox; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class peoplelist_customadapter extends ArrayAdapter<PeopleDetails>{ 

    Context context; 
    int layoutResourceId;  
    ArrayList<PeopleDetails> data = null; 

    public peoplelist_customadapter(Context context, int layoutResourceId, ArrayList<PeopleDetails> data) { 
     super(context, layoutResourceId, data); 
     this.layoutResourceId = layoutResourceId; 
     this.context = context; 
     this.data = data; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View row = convertView; 
     personHolder holder = null; 
     PeopleDetails[] people_array = data.toArray(new PeopleDetails[data.size()]); 


     if(row == null) 
     { 
      LayoutInflater inflater = ((Activity)context).getLayoutInflater(); 
      row = inflater.inflate(layoutResourceId, parent, false); 

      holder = new personHolder(); 
      holder.txtName = (TextView)row.findViewById(R.id.name_txt); 
      holder.txtNumber = (TextView)row.findViewById(R.id.number_txt); 
      holder.checkbox = (CheckBox) row.findViewById(R.id.checkBox); 
      row.setTag(holder); 
     } 
     else 
     { 
      holder = (personHolder)row.getTag(); 
     } 

     PeopleDetails person = people_array[position]; 
     holder.txtName.setText(person.name); 
     holder.txtNumber.setText(person.number); 

     ///CheckBox mCheckBox = (CheckBox) mView.findViewById(R.id.checkBox); 


     return row; 
    } 
    public boolean getView_IsChecked(int position){ 

    } 



    static class personHolder 
    { 
     TextView txtName; 
     TextView txtNumber; 
     CheckBox checkbox; 
     public boolean isChecked(){ 
      boolean isChecked_boolean = false; ///this holds the return value, of whether the checkbox is checked or not. 
      if(checkbox.isChecked()){ 
       isChecked_boolean = true; 
      } 
      else{ 
       isChecked_boolean = false; 
      } 
      return isChecked_boolean; 
     } 
    } 
} 
+0

어댑터 코드를 게시 할 수 있습니까? getItem()은 반환 할 객체를 반환해야합니다. – MikeHelland

답변

1

당신은 당신의 getView() 재정 내부의 체크 박스에 체크 여부를 결정하는 로직을 넣어해야합니다.

어댑터 외부의 어느 곳에서나 personHolder 클래스를 사용하면 안됩니다. 이는보기를 재생할 때만 사용하기위한 것입니다.

+0

getView()는 일반적으로 뷰를 반환하지만 부울을 원합니다. getView()는 ListView를 부 풀리는 데 사용되었다고 생각했습니다. –

+1

PeopleDetails 클래스의 내용에 따라보기가 확인되거나 표시되지 않습니다. 그렇습니까? 이 경우 getItem()을 호출하여 PeopleDetails를 가져오고 확인란을 선택했는지 동일한 논리로 알 수 있습니다. 사용자가 다른 질문 인 체크 박스를 토글 할 수있는 경우. –

+0

사용자는 체크 박스를 토글합니다. 확인 여부를 확인하는 가장 쉬운 방법은 무엇입니까? 그런 다음 별도의 arraylist에 추가 하시겠습니까 ?? 나는 검사 된 항목을 가져와 별도의 arraylist에 추가하고 다른 항목은 무시하고 싶습니다. –

관련 문제