2013-06-25 57 views
1

我正在android應用程序上工作。因爲我需要根據特定的尺寸動態顯示單選按鈕。我可以用1,2,3顯示單選按鈕。如何在android中動態顯示字母?

1. text1 
2. text2 
3. text3 

但我怎麼能顯示像單選按鈕下方

a. text1 
b. text2 
c. text3 

任何幫助會感激

+0

已谷歌它已經在stackoverflow..here(https://www.google.co.in/search?q=add+radio+button+dynamically+android&rlz=1C1LENP_enIN539IN539&oq=dynamically+add+radio+button+androi&aqs = chrome.2.57j0l3j62l2.10947j0&的SourceID =鉻&即= UTF-8) – KOTIOS

回答

0

你必須在佈局文件中創建一個RadioGroup中

<TableRow> 
    <RadioGroup 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:id="@+id/radiobuttons"> 
    </RadioGroup> 
</TableRow> 

,然後以編程按鈕添加到它,只要你想它設置文本,而不是數字:

public void makeRadioButtons(Vector tmpVector, int i, 
LinearLayout.LayoutParams lp) 
{ 
    RadioButton rb = new RadioButton(this); 
    rb.setText((String) tmpVector.elementAt(i)); 
    //rg is private member of class which refers to the radio group which you can find by id. 
    rg.addView(rb, 0, lp); 

} 

希望這有助於。

相關問題