2013-11-23 60 views
-3

我想創建一個表單,其中包含type_of_service,name,ph.no,...等。在服務類型中,類型是使用單選按鈕指定的。這是從asp webservice動態...它可能是1,2或10 .. 我必須從服務的類型中只選擇一個選擇...然後選擇選擇並填寫表單並點擊提交按鈕,我必須將選定的單選按鈕的值傳遞到支付網關(PayPal)...創建動態單選按鈕,並只檢查一個單選按鈕,並取消其他選項

我大概probs創建單選按鈕動態和選擇其中之一...並取消選擇其餘的單選按鈕... 以及如何檢查哪個單選按鈕被選中,所以我的傳遞相應的值..

plz幫助...

回答

1

試試這個..

LinearLayout layout_name = (LinearLayout) findViewById(R.id.layout_name); 
final RadioButton[] rb = new RadioButton[5]; 
     RadioGroup rg = new RadioGroup(this); //create the RadioGroup 
     rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL 
     for(int i=0; i<5; i++){ 
      rb[i] = new RadioButton(this); 
      rg.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout 
      rb[i].setId(i);//Setting id for the RadioButton 
      rb[i].setText("Test"); 
     } 
     rg.check(3);//Checking pirticular RadioButton with id 
     // 3 is that RadioButton Id name 
     layout_name.addView(rg);//you add the whole RadioGroup to the layout 

編輯:

int selected = rg.getCheckedRadioButtonId(); 
String type =rb[selected].getText().toString(); 
Log.d("type", type); 
+0

感謝烏拉圭回合的答覆.... :-) – user2833621

+0

@ user2833621檢查我的編輯。 – Hariharan

相關問題