2011-04-14 49 views
0
集團

我是新來的Java和黑莓,我只能堅持一個註冊屏幕,由於休耕:RadiobuttonField超與標籤,價值和

我有一個註冊畫面,在這裏我展示2個單選按鈕,男性和女性。只有這些「標籤」不適合我寫,這是我向web服務請求的價值和標籤。 我需要的是這樣的:

MyRadioButton rb1=(String label, String value, Group rbg); 

,它的超(標籤,值,組); ---這個值更多的是一個內部標籤ID,可以這麼說,一個pk_id .---

所以我可以,後,檢索哪個Rbutton被選中,它的價值,所以我可以發回它,當我點擊註冊按鈕。

我對如何做到這一點的例子,但並不適用於黑莓:

Gender[] gender = WebServCall.GetUserGender(); 

    if (gender != null && gender.length == 2) 
    { 

     holder.radiob1.setText(gender[0].genderType); 
     holder.radiob1.setTag(gender[0].PK_ID); 
     holder.radiob2.setText(gender[1].genderType); 
     holder.radiob2.setTag(gender[1].PK_ID); 



    } 
    else 
    { 
     //alert 
    } 
} 

static class ViewHolder 
{ 
    RadioButton radiob1; 
    RadioButton radiob2; 
} 

(...)

//獲取插入的信息,由用戶

。 .. RadioButton register_buffer_Gender1 =(RadioButton)findViewById(R.id.radiob1); RadioButton register_buffer_Gender2 =(RadioButton)findViewById(R.id.radiob2);

... 布爾型check1 = register_buffer_Gender1.isChecked(); 布爾check2 = register_buffer_Gender2.isChecked();

....

你能給並舉例如何做到這一點,但黑莓?

謝謝

回答

1

的做法實際上是在BlackBerry開發非常相似:

//Setting up the buttons 
RadioButtonGroup group = new RadioButtonGroup(); 

RadioButtonField radio1 = new RadioButonField(gender[0].genderType, group); 
radio1.setCookie(gender[0].PK_ID); 

RadioButtonField radio2 = new RadioButtoNField(gender[1].genderType, group); 
radio2.setCookie(gender[1].PK_ID); 

add(radio1); 
add(radio2); 

//////////////////////// 

//Retrieving info from the buttons 
boolean check1 = radio1.isSelected(); 
boolean check2 = radio2.isSelected(); 

//or you can use the group 
int checkedIndex = group.getSelectedIndex(); 

我建議考慮看看文件上RadioButtonFieldRadioButtonGroup,應該讓你對你的方式。

+0

我打算試試!非常感謝你!!! – csbl 2011-04-14 14:00:32

+0

是「MyRadioButton Gender1 = rb1;」同樣作爲 「RadioButton Gender1 =(RadioButton)findViewById(R.id.radiob1);」我如何做到這一點 「 \t \t如果(CHECK1) \t \t \t性別= Gender1.getTag()的toString();否則 \t性別= Gender2.getTag()的toString();」?這是爲了獲得性別價值,因此我可以在註冊時將它發回給網站。所有考慮我的第一篇文章。 – csbl 2011-04-14 14:34:48

+0

MyRadioButton是你在BB中使用的嗎?如果是,那麼是的,但你可以使用rb1而不需要爲其分配另一個變量。關於第二部分,您可以使用rb1(或Gender1,如果您正在重新分配)並調用rb1.getLabel()來獲取RadioButton的文本,或者如果您試圖從中獲取PK_ID,您可以調用rb1.getCookie()。toString(),假設PK_ID是一個String。 – jprofitt 2011-04-14 15:39:34