2017-03-29 2 views
0

リストビューのリスト項目の内側に4つのラジオボタンのラジオグループを使用しようとしています。リストをスクロールするとラジオボタンの状態が変わります。私はこれを探しましたが、コードを変更する方法を理解していません。私はアンドロイドに新しい。状態を変更せずにリストビュー内のリストアイテム内でラジオグループを使用する方法は?

マイカスタムアダプタのコード:

public class AttendanceInputListAdapter extends ArrayAdapter<TodaysClasses> { 

    Context context; 
    static ArrayList<Integer> action; 
    public static ArrayList<TodaysClasses> daySubjects; 

    public AttendanceInputListAdapter(Activity context, ArrayList<TodaysClasses> allTodaysClasses) { 
     super(context,0,allTodaysClasses); 
     daySubjects = allTodaysClasses; 
    } 

    @NonNull 
    @Override 
    public View getView(final int position, final View convertView, ViewGroup parent) { 

     View listItemView = convertView; 
     if(listItemView == null){ 
      listItemView = LayoutInflater.from(getContext()).inflate(R.layout.day_classes_listitem,parent,false); 
     } 

     action = new ArrayList<>(); 
     for (int i = 0; i < daySubjects.size(); i++) { 
      action.add(0); 
     } 

     TodaysClasses currentItem = getItem(position); 

     TextView SubjectName = (TextView)listItemView.findViewById(R.id.SubjectNameAttendanceInput); 
     assert currentItem != null; 
     SubjectName.setText(currentItem.getSubjectName()); 

     RadioButton attended = (RadioButton)listItemView.findViewById(R.id.Attended); 
     attended.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
       if (b) 
        action.set(position,1); 
      } 
     }); 

     RadioButton absent = (RadioButton)listItemView.findViewById(R.id.absent); 
     absent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
       if (b) 
        action.set(position,2); 
      } 
     }); 

     RadioButton cancled = (RadioButton)listItemView.findViewById(R.id.classCanceled); 
     cancled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
       if (b) 
        action.set(position,3); 
      } 
     }); 

     Button changeSubject = (Button)listItemView.findViewById(R.id.changeSubjectButton); 
     changeSubject.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       FragmentManager manager = ((Activity)context).getFragmentManager(); 
       ChandSubjectDialog pop = new ChandSubjectDialog(); 
       pop.show(manager, "No Of classes a day"); 

      } 
     }); 

     return listItemView; 
    } 

} 

はありがとうございました...私を助けてください。

+0

@Uknight plzは無料でお世話になっています。 –

+0

@AnjaliTripathi –

+0

ラジオグループのLisrViewは、このようなばかげた考えです – Devon

答えて

0

radioGroupを使用してradioGroupを使用するだけです。 radioGroupとともにradioGroupでLisrViewを使用しないでください。

関連する問題