2017-09-25 69 views
0

當我點擊TextView參考時,我得到AlertDialog建設者,因爲我正在顯示employeesNames列表和RadioButtons。現在,當我檢查了錯誤的Employee並且我想選擇另一個employee時,應該取消選中錯誤的employee名稱,並且通過選擇一個Employee,應該啓用okButton一次只選擇一個RadioButton

delivery.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      LayoutInflater inflater1 = (LayoutInflater) ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View v1 = inflater1.inflate(R.layout.activity_employees_list_for_pop_up, null); 
      RadioButton employeechecked = (RadioButton) v1.findViewById(R.id.employeeChecked); 
      final Button ok = (Button) v1.findViewById(R.id.do_ok); 
      Button cancle = (Button) v1.findViewById(R.id.do_cancle); 
      ok.setEnabled(false); 
      listView = (ListView) v1.findViewById(R.id.employeePopUpList); 
      employeePopUpAdapter = new EmployeePopUpAdapter(ct, employeeIdNameBeans); 

      employeechecked.setOnCheckedChangeListener(new); 


      listView.setAdapter(employeePopUpAdapter); 

      AlertDialog.Builder builder; 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       builder = new AlertDialog.Builder(ct, android.R.style.Theme_Material_Dialog_Alert); 
      } else { 
       builder = new AlertDialog.Builder(ct); 
      } 
      builder.setView(v1); 
      builder.create().show(); 
      clearListView(); 
      update(); 
     } 
    }); 

請幫助我的編碼不張貼理論,我不明白我是一個初學者。

+0

必須使用RadioGroup中,或以編程方式處理它 –

+0

如何使用無線電組列表視圖? –

回答

1

您可以嘗試RadioGroup而不是RadioButton。

<RadioGroup 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:id="@+id/a" 
    android:onClick="onRGClick"> 

    <RadioButton 
     android:text="Normal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/a1" /> 

    <RadioButton 
     android:text="Tidak normal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/a2" /> 

</RadioGroup> 

,並嘗試setOnCheckedChangeListener方法的選擇和檢索所選擇的項目

radiogroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
    @Override 
    public void onCheckedChanged(RadioGroup group, int checkedId) { 
     if (checkedId == R.id.a1) { 
      // do your stuff 
     } else if (checkedId == R.id.a2) { 
      // do your stuff 
     } 
    } 
}); 
+0

再次閱讀問題 –

+0

在這種情況下,您可以使用android checkable listview – Saravanan