效果如图,这是一道心理测试题,可以测试为人

这种效果在界面上用CheckBox实现,逻辑上用OnCheckedChangeListener***给每个复选框监听,监听方法就是在下方输出字符串
xml中我们用线性布局,CheckBox继承自CompoundButton,所以他也是Button的一种,和
Button写法类似

<LinearLayout  android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
    <TextView  android:id="@+id/question" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="假如你在沙漠很口渴,找到一间屋子,摆在你前面的是一块切好的西瓜,一瓶水,一个果冻,你会选择?" app:layout_constraintTop_toTopOf="parent" android:textSize="30sp" />
    <CheckBox  android:id="@+id/watermelon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:layout_marginTop="20dp" android:text="西瓜">
    </CheckBox>
    <!--id前少写+号,将会导致这个id必须和上面一个CheckBox一样,否则报错,所以要细心-->
    <CheckBox  android:id="@+id/water" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:layout_marginTop="20dp" android:text="水">
    </CheckBox>
    <CheckBox  android:id="@+id/jelly" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:layout_marginTop="20dp" android:text="果冻">
    </CheckBox>
    <TextView  android:id="@+id/answer" android:text="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:textSize="30sp" />

</LinearLayout>

需要指出的是OnCheckedChangeListener 有两种参数的接口
一种是接下来要用到的配CheckBox的
public interface OnCheckedChangeListener {
void onCheckedChanged(CompoundButton var1, boolean var2);
}
另一种是配RadioGroup的,单选框的
public interface OnCheckedChangeListener {
void onCheckedChanged(RadioGroup var1, int var2);
}

package com.example.a18307.link;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    CheckBox checkBox1;
    CheckBox checkBox2;
    CheckBox checkBox3;
    TextView textView;
    private ArrayList<String>strings;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//获取界面上的Check和Textview
        checkBox1=(CheckBox)findViewById(R.id.watermelon);
        checkBox2=(CheckBox)findViewById(R.id.water);
        checkBox3=(CheckBox)findViewById(R.id.jelly);
        textView=(TextView)findViewById(R.id.answer);
//给三个按钮分别添加***
        checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener());
        checkBox2.setOnCheckedChangeListener(new OnCheckedChangeListener());
        checkBox3.setOnCheckedChangeListener(new OnCheckedChangeListener());

    }
    //这里的OnCheckedChangeListener继承自CompoundButton
    public class OnCheckedChangeListener implements CompoundButton.OnCheckedChangeListener{

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            String string="";
            if(checkBox1.isChecked())string=string+","+checkBox1.getText();
            if(checkBox2.isChecked())string=string+","+checkBox2.getText();
            if(checkBox3.isChecked())string=string+","+checkBox3.getText();

//消除第一个逗号,用subString方法取了字符串从第二个字符到最后的内容 
if(string.indexOf(",")==0)string=string.substring(1,string.length());
            textView.setText("你选中了"+ string);
        }
    }

}

最后,如果你选择的是西瓜,那么证明!!

———————————分割线—————————————

你喜欢吃西瓜!