0
我有一個按鈕,我希望當我點擊它去頁面片段單選按鈕被檢查,如果,例如,它是一個你好,單詞你好打印在textview中頁面MainActivity檢查頁面片段中的單選按鈕
頁面片段
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.java.frag.BlankFragment">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:text="nice to meet you"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:layout_weight="1" />
<RadioButton
android:text="welcome"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2"
android:layout_weight="1" />
<RadioButton
android:text="hello"
android:textStyle="bold"
android:layout_gravity="center"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton3"
android:layout_weight="1" />
</RadioGroup>
</LinearLayout>
頁MainActivity
package com.example.java.frag;
import android.app.FragmentTransaction;
import android.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView x = (TextView)findViewById(R.id.textView);
}
public void changetext(View view) {
FragmentManager frag = getFragmentManager();
FragmentTransaction tran = frag.beginTransaction();
BlankFragment s = new BlankFragment();
tran.replace(R.id.con,s);
tran.commit();
}
}
我該怎麼辦呢?
我希望得到一個例子