-2
我是新來android,我的要求是選擇一個單選按鈕,並在Android中相應的活動? 任何人都可以幫助我嗎? 在此先感謝.......如何選擇一個單選按鈕,並在android中進入該活動?
我是新來android,我的要求是選擇一個單選按鈕,並在Android中相應的活動? 任何人都可以幫助我嗎? 在此先感謝.......如何選擇一個單選按鈕,並在android中進入該活動?
所有你需要的在那些兩位導遊解釋:
下面是這樣的一個例子您。這是XML佈局有兩個分組單選按鈕:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RadioButton
android:id="@+id/radiobutton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="radio 1"
/>
<RadioButton
android:id="@+id/radiobutton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="radio 2"/>
</RadioGroup> </LinearLayout>
在OnCreate爲您的活動,您的setContentView上述觀點後,找到單選按鈕和設置檢查聽衆。
RadioButton buttonOne = (RadioButton)findViewById(R.id.radiobutton1);
buttonOne.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
//Go to the activity for button 1 here
MainActivity.this.startActivity(new Intent(MainActivity.this, ActivityYouWantToGoTo.class));
}
}
});
RadioButton buttonTwo = (RadioButton)findViewById(R.id.radiobutton2);
buttonTwo.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
//Go to the activity for button 2 here
MainActivity.this.startActivity(new Intent(MainActivity.this, ActivityYouWantToGoTo.class));
}
}
});
}
你至少試過做過什麼嗎?我的意思是......你有複選框已編程?如果是這樣,請你提供代碼,以便我們提供幫助? – Cristian 2010-11-19 16:38:41