这是适配器类.....
public View getView(final int position, View convertView, ViewGroup parent)
{
ViewHolder holder=null;
Student temp = (Student) getItem(position);
if (convertView == null)
{
convertView = mInflator.inflate(R.layout.item_class_student, null);
holder = new ViewHolder();
holder.nameTextView = (TextView) convertView.findViewById(R.id.row_student_name);
holder.classTextView = (TextView) convertView.findViewById(R.id.row_student_class);
holder.rollNumberTextView = (TextView) convertView.findViewById(R.id.row_student_roll_number);
holder.image = (ImageView) convertView.findViewById(R.id.row_student_image);
//holder.checkBox=(CheckBox) convertView.findViewById(R.id.cb_student_selected);
holder.mgroup=(RadioGroup) convertView.findViewById(R.id.rg_list);
holder.pre=(RadioButton) convertView.findViewById(R.id.rb_present);
holder.abs=(RadioButton) convertView.findViewById(R.id.rb_absent);
holder.leave=(RadioButton) convertView.findViewById(R.id.rb_leave);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
//Student temp = (Student) getItem(position);
holder.nameTextView.setText(temp.getName());
holder.rollNumberTextView.setText("Roll No: " + temp.getRollNumber());
holder.classTextView.setText(temp.getStudClass() + "");
if(!flag)
{
holder.mgroup.setVisibility(View.GONE);
}
// Set Image
if (temp.getPhoto() != null)
{
mImageLoader.displayImage(temp.getPhoto(), holder.image, mOptions);
}
else
{
holder.image.setImageResource(R.drawable.img_default_profile);
}
if(temp.isChecked())
{
holder.abs.setChecked(true);
holder.pre.setChecked(false);
holder.leave.setChecked(false);
//Toast.makeText(activity, "A", Toast.LENGTH_SHORT).show();
}
else if(temp.isChecked())
{
holder.abs.setChecked(false);
holder.pre.setChecked(true);
holder.leave.setChecked(false);
//Toast.makeText(activity, "P", Toast.LENGTH_SHORT).show();
}
else if(temp.isChecked())
{
holder.abs.setChecked(false);
holder.pre.setChecked(false);
holder.leave.setChecked(true);
//Toast.makeText(activity, "L", Toast.LENGTH_SHORT).show();
}
holder.mgroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
View radioButton = group.findViewById(checkedId);
int radioId = group.indexOfChild(radioButton);
boolean checked = ((RadioButton) radioButton).isChecked();
System.out.println("ID" + radioButton.getId());
switch (radioId)
{
case R.id.rb_present:
if(checked)
{
flagPresent[position]=true;
flagAbsent[position]=false;
flagLeave[position]=false;
}
break;
case R.id.rb_absent:
if(checked)
{
flagPresent[position]=false;
flagAbsent[position]=true;
flagLeave[position]=false;
}
break;
case R.id.rb_leave:
if(checked)
{
flagPresent[position]=false;
flagAbsent[position]=false;
flagLeave[position]=true;
}
break;
}
//students.set(position, temp);
//refreshList(students, position);
}
});
return convertView;
}
这是Sudent Modal Class,其中数据被设置.....
public class Student implements Parcelable {
private String name;
private String rollNumber;
private String regId;
private String studClass;
private String photo;
private boolean checked;
private String status;
public Student() {
}
public Student(Parcel in) {
this.name = in.readString();
this.rollNumber = in.readString();
this.regId = in.readString();
this.studClass = in.readString();
this.photo = in.readString();
}
/**
* @return the checked
*/
public boolean isChecked()
{
return checked;
}
public void setChecked(boolean checked)
{
this.checked = checked;
}