這是我arrayadapter的代碼,將設置單選按鈕狀態:RadioButton.setChecked()不出現工作
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
attendance_holder holder = null;
People_Attendance people_array[] = people_attendance.toArray(new People_Attendance[people_attendance.size()]);
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new attendance_holder();
holder.txtName = (TextView)row.findViewById(R.id.name_txt);
holder.txtNumber = (TextView)row.findViewById(R.id.number_txt);
holder.attendance_group = row.findViewById(R.id.Attendance_Group);
holder.not_attending = (RadioButton) holder.attendance_group.findViewById(R.id.not_attending_radio);
holder.attending = (RadioButton) holder.attendance_group.findViewById(R.id.attending_radio);
holder.invited = (RadioButton) holder.attendance_group.findViewById(R.id.invited_radio);
row.setTag(holder);
}
else
{
holder = (attendance_holder)row.getTag();
}
holder.txtName.setText(people_array[position].name);
holder.txtNumber.setText(people_array[position].number);
if (people_array[position].attendance_status == "INVITED"){
holder.invited.setChecked(true);
}else if(people_array[position].attendance_status == "ATTENDING"){
holder.attending.setChecked(true);
}else if(people_array[position].attendance_status == "NOT ATTENDING"){
holder.not_attending.setChecked(true);
}else{
Log.d("ATTENDANCE", people_array[position].attendance_status);
}
return row;
}
我已經使用了Log.d()在我的代碼,以顯示字符串,所以我知道這不是一個空字符串或壞字符串,這是問題。因此我會認爲我的if語句在某些方面是錯誤的,或者我使用RadioButton.setChecked()錯誤。然後RadioButtons不會按照他們應該做的方式進行檢查。 RadioButtons在RadioGroup中。
任何想法??
感謝您的幫助!
張貼完成getView code – Triode
@RajeshCP我有。 :) –
可能重複[如何比較Java中的字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Reimeus