2016-04-23 24 views
0

Inリストビューに含まれる自分のアクティビティ。リストビューの行には、TextGroupが1つ、RadioGroupに3つのラジオボタンが含まれています。リストをスクロールした後に最初のラジオボタンを選択すると、10行後に自動的に選択された最初のラジオボタンが表示されます。これは10行ごとに発生します。ListviewでRadioGroupを使用しているスクロールの問題?

public class StudentAttendanceCustomAdapter extends BaseAdapter{ 

    private Activity activity; 
    private LayoutInflater inflater; 
    private List<StudentDataReader> studentRecord; 
    private List<StudentDataReader> mOriginalValues; 
    public HashMap<String, String> radioMap; 
    private int mSelectedPosition = -1, radioButtonId; 

    public StudentAttendanceCustomAdapter(TeacherAttendanceActivity activity, List<StudentDataReader> studentList) { 

     this.activity = activity; 
     this.studentRecord = studentList; 
     this.mOriginalValues = studentList; 
    } 

    @Override 
    public int getCount() { 
     return studentRecord.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return studentRecord.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    static class ViewHolder{ 
     TextView studentName; 
     RadioButton rb_p; 
     RadioButton rb_a; 
     RadioButton rb_l; 
     RadioGroup rg; 

    } 
    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     ViewHolder hoder = new ViewHolder(); 
     if (inflater == null) 
     { 
      inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     } 
     if(convertView == null){ 
      convertView = inflater.inflate(R.layout.teacher_attendance_row,parent,false); 

      hoder.studentName = (TextView)convertView.findViewById(R.id.tv_attendance_studentName); 
      hoder.rg = (RadioGroup)convertView.findViewById(R.id.rg_1); 
      hoder.rb_p = (RadioButton)convertView.findViewById(R.id.radioButton_present); 
      hoder.rb_a = (RadioButton)convertView.findViewById(R.id.radioButton_absent); 
      hoder.rb_l = (RadioButton)convertView.findViewById(R.id.radioButton_leave); 
      convertView.setTag(hoder); 
     }else { 
      hoder = (ViewHolder)convertView.getTag(); 
     } 

     final String str_studentId,str_studentName; 
     final StudentDataReader s = studentRecord.get(position); 
     hoder.studentName.setText(s.getStudentName()); 
     str_studentId= s.getStudentId(); 
     str_studentName = s.getStudentName(); 


     hoder.rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup group, int checkedId) { 
       int childCount = group.getChildCount(); 

       for (int i = 0; i < childCount; i++) { 
        RadioButton radioButton = (RadioButton) group.getChildAt(i); 

        if (radioButton.getId() == checkedId) { 
         s.setPresent(radioButton.getText().toString()); 
         notifyDataSetChanged(); 
        } 
       } 
      } 
     }); 

     return convertView; 
    } 
} 

CustomAdapterクラスは、いずれも事前に私に感謝を助けてください。

+0

これをチェックすることができます - http://stackoverflow.com/a/35862385/2128166 それは異なるデータを持っていますが、ラジオボタンの状態をどのように保持できるかを参考にすることができます。 – androidnoobdev

答えて

0

ビューの所有者はビューの状態を保持します。各アイテムについては、データを保持したり、アダプタに配列したり、アイテムオブジェクトデータを置く必要があります。

+0

再生に感謝しますが、私はそれを実装する方法がわかりません。助けてください – Shailesh

+0

と仮定すると、アイテムはYourDataオブジェクトを表示します。このオブジェクトにselectedRadioPositionというプロパティを追加できます。ユーザーがラジオをクリックしてこの位置を取得し、selectedRadioPositionに設定します。取得するにはこのポジションのラジオボタンの設定を確認してください –

+0

可能であれば、私は自分のJavaコードをどこで更新できるのか教えてください。どういうタイプの変更をお願いしますか? – Shailesh

関連する問題