List<String> list = new ArrayList<String>();
list.add("none,i am healthy");
list.add("Diabetes");
list.add("cancer");
list.add("HIV/AIDS");
list.add("Tuberculosis");
list.add("Coronary Artery");
list.add("respiratory disease");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.support_simple_spinner_dropdown_item, list);
// dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
spinner1.setOnItemSelectedListener(this);
List <String>list = new ArrayList <String>();
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.get(position).equals("Diabetes")) {
String name = editText.getText().toString();
int c = b;
int x = c - 5 ;
editText3.setText(name + " you might die in the year" + c + "");
As you can see i have called in editText3 after a selection made by the user but as you can also see that i have defined int c = b . where as the b is the variable used in button click listener . i am also giving the code of button click listener
button.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View view) {
String name = editText.getText().toString();
if (yes.isChecked()) {
int age = Integer.parseInt(ageText.getText().toString());
int c;
int b ;
int l;
l = 80 ;
int y ;
y = l - age ;
c = y - 7;
final int z;
b = 2016 + c;
editText3.setText((name + " you might die in the year" + b) + "");
} else {
if (no.isChecked()) {
int age = Integer.parseInt(ageText.getText().toString());
int c;
int b;
int l;
l = 80;
int y;
y = l - age;
c = y + 10;
b = 2016 + c;
editText3.setText((name + "you might die in the year" + b) + "");
}
}
}
});
now in this button you can see that the ultimate result was b . now i want to use the int value of b in spinner . i.e. the spinner would add or decrease the value of the variable b on selection from the user .