我尝试设计这个:
enter image description here
但我不知道如何修复
public class MainActivity extends AppCompatActivity
{
private Button btn;
private EditText et1;
private RadioButton A;
private RadioButton B;
private RadioButton O;
private RadioButton AB;
private RadioGroup rgroup;
Spinner部分:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner)findViewById(R.id.spinner);
final String[] lunch = {"Doctor", "Master", "Bachelor"};
ArrayAdapter<String> lunchList = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, lunch);
spinner.setAdapter(lunchList);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new Information());
}
使用按钮显示消息:
private class Information implements OnClickListener
{
public void onClick(View view)
{
rgroup = (RadioGroup) findViewById(R.id.rgroup);
final String[] lunch = {"Doctor", "Master", "Bachelor"};
Spinner spinner = (Spinner) findViewById(R.id.spinner);
A = (RadioButton) findViewById(R.id.A);
B = (RadioButton) findViewById(R.id.B);
O = (RadioButton) findViewById(R.id.O);
AB = (RadioButton) findViewById(R.id.AB);
AlertDialog.Builder ad = new AlertDialog.Builder(MainActivity.this);
EditText input = (EditText) findViewById(R.id.et1);
int checkedRadioButtonId = rgroup.getCheckedRadioButtonId();
这部分是放映RadioButton和Spinne消息:
ad.setTitle("Information");
switch (checkedRadioButtonId)
{
case R.id.A:
ad.setMessage(input.getText() + " with blood type " +
A.getText() + " and " + lunch[?] + " degree");
break;
case R.id.B:
ad.setMessage(input.getText() + " with blood type " +
B.getText() + " and " + lunch[?] + " degree");
break;
case R.id.O:
ad.setMessage(input.getText() + " with blood type " +
O.getText() + " and " + lunch[?] + " degree");
break;
case R.id.AB:
ad.setMessage(input.getText() + " with blood type " +
AB.getText() + " and " + lunch[?] + " degree");
break;
}
//ad.setTitle("Information");
ad.setNeutralButton("Confirm", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
});
ad.show();
input.setText("");
}
}
}
但我不知道如何修复或添加任何内容:
ad.setMessage(input.getText() + " with blood type " + A.getText() + " and
" + lunch[?] + " degree");
它将是: 爱丽丝有血型B和博士/硕士/学士(根据我选择)学位。
答案 0 :(得分:0)
取而代之的是input.getText();
或A.getText();
使用input.getText().toString();
和A.getText().toString();