Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中选择一个单选按钮并转到该活动?_Android - Fatal编程技术网

如何在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="ver

我是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>
      

      你至少试过做点什么吗?我是说。。。您是否已经对复选框进行了编程?如果是这样,请提供代码以便我们提供帮助?
          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));
                  }
              }
          });
      }