Android开发模拟测试题

IT人员测试应用:

效果图:
在这里插入图片描述
布局设置三个文本框和两个RadioGroup

<TextView
    android:id="@+id/myTextView"
    android:layout_width="228px"
    android:layout_height="49px"
    android:text="测试结果"
    android:textSize="15sp"
    />
<TextView
    android:id="@+id/t1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="你了解windows操作系统吗"
    />

<RadioGroup
    android:id="@+id/myRadioGroup"
    android:layout_width="137px"
    android:layout_height="216px"
    android:orientation="vertical">
 
    <RadioButton
        android:id="@+id/myRadioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="精通"
        />
    <RadioButton
        android:id="@+id/myRadioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="一般"
        />
    
    <RadioButton
        android:id="@+id/myRadioButton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="陌生"
        />
</RadioGroup>


<TextView
    android:id="@+id/t2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="你了解编程语言吗"
    />

<RadioGroup
    android:id="@+id/myRadioGroup2"
    android:layout_width="137px"
    android:layout_height="216px"
    android:orientation="vertical">
    <RadioButton
        android:id="@+id/myRadioButton21"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="精通各种语言"
        />
    <RadioButton
        android:id="@+id/myRadioButton22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="了解c语言"
        />
    
    <RadioButton
        android:id="@+id/myRadioButton23"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="只会说汉语"
        />
</RadioGroup>

设置好对象,最后利用if条件判断选项得出结果

package com.example.it;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
  
public class MainActivity extends Activity {
    public TextView mTextView1;
    public RadioGroup mRadioGroup1,mRadioGroup2;
    public RadioButton mRadio1, mRadio2, mRadio3, mRadio4, mRadio5, mRadio6;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
  
        // 取得 TextView、RadioGroup、RadioButton对象
        mTextView1 = (TextView) findViewById(R.id.myTextView);
        mRadioGroup1 = (RadioGroup) findViewById(R.id.myRadioGroup);
        mRadioGroup2 = (RadioGroup) findViewById(R.id.myRadioGroup2);
        mRadio1 = (RadioButton) findViewById(R.id.myRadioButton1);
        mRadio2 = (RadioButton) findViewById(R.id.myRadioButton2);
        mRadio3 = (RadioButton) findViewById(R.id.myRadioButton3);
        mRadio4 = (RadioButton) findViewById(R.id.myRadioButton1);
        mRadio5 = (RadioButton) findViewById(R.id.myRadioButton2);
        mRadio6 = (RadioButton) findViewById(R.id.myRadioButton3);
  
        // RadioGroup用OnCheckedChangeListener来运行
        mRadioGroup1.setOnCheckedChangeListener(mChangeRadio);
    }
  
    private RadioGroup.OnCheckedChangeListener mChangeRadio = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub
            if (checkedId == mRadio1.getId()&&checkedId == mRadio4.getId()) {
                mTextView1.setText("您是IT达人");
            } else  {
                mTextView1.setText("您不是IT达人");
            }
        }
    };
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页