final Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
spinner1.setOnItemSelectedListener(this);
List list = new ArrayList ();
list.add("Diabetes");
list.add("cancer");
list.add("HIV/AIDS");
list.add("Tuberculosis");
list.add("respiratory disease");
list.add("Coronary Artery");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.getSelectedItemPosition();
if (list.equals("Diabetes")){
int x ;
int c ;
x = z-5;
c = 2016 + x;
editText3.setText((name + " you might die in the year " + c) + "");
编辑1 - 程序正在运行(完美执行)但是微调器功能无法正常工作。帮助我。我正在创建一个死亡计算器,用户必须输入他的年龄,然后他必须从微调器中选择(包含疾病名称)。 现在,微调器不工作(程序正在运行并执行,但微调器功能不起作用
button.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View view) {
CheckBox yes = (CheckBox) findViewById(R.id.yes);
CheckBox no = (CheckBox) findViewById(R.id.no);
EditText ageText = (EditText) findViewById(R.id.ageText);
EditText editText = (EditText) findViewById(R.id.editText);
final EditText editText3 = (EditText) findViewById(R.id.editText3);
final String name = editText.getText().toString();
if (yes.isChecked()) {
int age = Integer.parseInt(ageText.getText().toString());
int c;
c = age - 7;
final int z;
z = 2016 + c;
editText3.setText((name + " you might die in the year " + z) + "");
} else if (no.isChecked()) {
final int age = Integer.parseInt(ageText.getText().toString());
int c;
c = age + 10;
final int z;
z = 2016 + c;
editText3.setText((name + " you might die in the year " + z) + "");
这是按钮监听器,为您提供解决方案会很有帮助。
问候
答案 0 :(得分:0)
Spinner spinner1 =(Spinner)findViewById(R.id.spinner1);
Label1