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;
}
}
}
어댑터 코드를 게시 할 수 있습니까? getItem()은 반환 할 객체를 반환해야합니다. – MikeHelland