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 .
Related
I've been trying for some days now to figure out why I am not getting a proper output from my app. No errors are showing up in logcat to explain why the output is "NaN" and not the value I'm attempting o calculate. Could someone show me the mistake(s) that I've made? It's a calculator app for my final year school project and I've tried to rectify the issue albeit without much success.
Here is the Main class for the app.
I've tried pretty much anything that has been suggested in various forums for similar issues.
public String educationStr, ethnicity, ldlStr, hdlStr, ageStr, tcStr, sysBPStr, diaBPStr;
public int married=0, education=0, educationSec=0, educationTert=0;
public int smoker=0, ethnicityChk=0;
public int highCholesterol=0;
public int atrialFibrillation=0;
public int familialCVD=0;
public int hypertension=0;
public int sex=0;
public int age=0;
public double tcVal = 0;
public double hdlVal=0;
public double ldlVal = 0;
public int sysBPval = 0;
public int diaBPval = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch_calculator);
//spinner for sex choices
Spinner spinnerSex = findViewById(R.id.sexSelect);
ArrayAdapter<CharSequence> adapterSex = ArrayAdapter.createFromResource(this, R.array.SexChoices, simple_spinner_item);
adapterSex.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerSex.setAdapter(adapterSex);
spinnerSex.setOnItemSelectedListener(this);
//spinner for marriage choices
Spinner spinnerMarried = findViewById(R.id.marriedSelect);
ArrayAdapter<CharSequence> adapterMarried = ArrayAdapter.createFromResource(this, R.array.YN, simple_spinner_item);
adapterMarried.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerMarried.setAdapter(adapterMarried);
spinnerMarried.setOnItemSelectedListener(this);
//spinner for Ethnicity
Spinner spinnerEthnicity = findViewById(R.id.ethnicitySelect);
ArrayAdapter<CharSequence> adapterEthnicity = ArrayAdapter.createFromResource(this, R.array.EthnicChoices, simple_spinner_item);
adapterEthnicity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerEthnicity.setAdapter(adapterEthnicity);
spinnerEthnicity.setOnItemSelectedListener(this);
//spinner for education
Spinner spinnerEducation = findViewById(R.id.EduLevelSpin);
ArrayAdapter<CharSequence> adapterEducation = ArrayAdapter.createFromResource(this, R.array.EduLevel, simple_spinner_item);
adapterEducation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerEducation.setAdapter(adapterEducation);
spinnerEducation.setOnItemSelectedListener(this);
//spinner for smoking history
Spinner spinnerSmoker = findViewById(R.id.smokerSelect);
ArrayAdapter<CharSequence> adapterSmoker = ArrayAdapter.createFromResource(this, R.array.smoke, simple_spinner_item);
adapterSmoker.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerSmoker.setAdapter(adapterSmoker);
spinnerSmoker.setOnItemSelectedListener(this);
//spinner for family health --> high cholesterol
Spinner spinnerHighCholesterol = findViewById(R.id.highCholesterolSelect);
ArrayAdapter<CharSequence> adapterHighCholesterol = ArrayAdapter.createFromResource(this, R.array.YN, simple_spinner_item);
adapterHighCholesterol.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerHighCholesterol.setAdapter(adapterHighCholesterol);
spinnerHighCholesterol.setOnItemSelectedListener(this);
//spinner for family health --> A Fib
Spinner spinnerAFib = findViewById(R.id.atrialFibrillationSelect);
ArrayAdapter<CharSequence> adapterAFib =
ArrayAdapter.createFromResource(this, R.array.YN, simple_spinner_item);
adapterAFib.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown
item);
spinnerAFib.setAdapter(adapterAFib);
spinnerAFib.setOnItemSelectedListener(this);
//spinner for family health --> Hypertension
Spinner spinnerHypertension = findViewById(R.id.HBPSpinSelect);
ArrayAdapter<CharSequence> adapterHypertension =
ArrayAdapter.createFromResource(this, R.array.YN,
simple_spinner_item);
adapterHypertension.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spinnerHypertension.setAdapter(adapterHypertension);
spinnerHypertension.setOnItemSelectedListener(this);
//spinner for family health --> Hypertension
Spinner spinnerFamilialCVD = findViewById(R.id.familialCVDSpin);
ArrayAdapter<CharSequence> adapterFamilialCVD =
ArrayAdapter.createFromResource(this, R.array.YN,
simple_spinner_item);
adapterFamilialCVD.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spinnerFamilialCVD.setAdapter(adapterFamilialCVD);
spinnerFamilialCVD.setOnItemSelectedListener(this);
//declaring button
final Button BtnSave = findViewById(R.id.btnSaveNsend);
BtnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.ageEnter:
EditText enterAge = findViewById(R.id.ageEnter);
ageStr = enterAge.getText().toString();
age = Integer.valueOf(ageStr);
break;
case R.id.sysBPEnter:
EditText enterSys = findViewById(R.id.sysBPEnter);
sysBPStr = enterSys.getText().toString();
sysBPval = Integer.valueOf(sysBPStr);
break;
case R.id.diaBPEnter:
EditText enterDia = findViewById(R.id.diaBPEnter);
diaBPStr = enterDia.getText().toString();
diaBPval = Integer.valueOf(diaBPStr);
break;
case R.id.tcEnter:
EditText enterTC = findViewById(R.id.tcEnter);
tcStr = enterTC.getText().toString();
tcVal = Integer.valueOf(tcStr);
break;
case R.id.hdlEnter:
EditText enterHDL = findViewById(R.id.hdlEnter);
hdlStr = enterHDL.getText().toString();
hdlVal = Integer.valueOf(hdlStr);
break;
case R.id.ldlEnter:
EditText enterLDL = findViewById(R.id.ldlEnter);
ldlStr = enterLDL.getText().toString();
ldlVal = Integer.valueOf(ldlStr);
}
if (ethnicityChk == 1){
Intent RiskCalc1 = new
Intent(getApplicationContext(),displayLinRiskResult.class);
startActivity(RiskCalc1);
} else if (ethnicityChk == 2){
Intent RiskCalc2 = new
Intent(getApplicationContext(),displayDiscrimRiskResult.class);
startActivity(RiskCalc2);
}
}
});
}
#Override
public void onItemSelected(AdapterView<?>
adapterView, View view, int i, long l) {
switch(adapterView.getId()){
case R.id.sexSelect:
String sexStr = adapterView.getSelectedItem().toString();
if (sexStr.equalsIgnoreCase("female")){
sex = 1;
}
else if (sexStr.equalsIgnoreCase("male")){
sex = 0;
}
//Toast.makeText(adapterView.getContext(), sex,
Toast.LENGTH_SHORT).show();
break;
case R.id.marriedSelect:
String marriedStr = adapterView.getSelectedItem().toString();
if (marriedStr.equalsIgnoreCase("YES")){
married = 1;
}
else if (marriedStr.equalsIgnoreCase("NO")){
married = 0;
}
//Toast.makeText(adapterView.getContext(), married,
Toast.LENGTH_SHORT).show();
break;
case R.id.smokerSelect:
String smokerStr = adapterView.getSelectedItem().toString();
if (ethnicity.equalsIgnoreCase("Afro-Caribbean"))
{if (smokerStr.equalsIgnoreCase("Smoker")){
smoker = 1;
}
else if (smokerStr.equalsIgnoreCase("Non-smoker")){
smoker = 0;
} }
else if (ethnicity.equalsIgnoreCase("Mixed-Caribbean")){
{if (smokerStr.equalsIgnoreCase("Smoker")){
smoker = 0;
}
else if (smokerStr.equalsIgnoreCase("Ex-smoker")){
smoker = 1;
} }}
// Toast.makeText(adapterView.getContext(), smokerStr,
Toast.LENGTH_SHORT);
break;
case R.id.ethnicitySelect:
ethnicity = (String) adapterView.getSelectedItem();
if (ethnicity.equals("Afro-Caribbean")||
(ethnicity.equals("Indo-Caribbean"))){
ethnicityChk = 1;
}
else if (ethnicity.equals("Mixed-Caribbean")){
ethnicityChk = 2;
}
//Toast.makeText(adapterView.getContext(), ethnicityStr,
Toast.LENGTH_SHORT);
break;
case R.id.EduLevelSpin:
educationStr = (String) adapterView.getSelectedItem();
//Toast.makeText(adapterView.getContext(),education,
Toast.LENGTH_SHORT);
if (educationStr.equalsIgnoreCase("Secondary")){
educationSec = 1;
educationTert = 0;
education = 1;
}
else if (educationStr.equalsIgnoreCase("Tertiary")){
educationSec = 1;
educationTert = 1;
education = 1;
}
else {
education = 1;
educationSec = 0;
educationTert = 0;
}
break;
case R.id.highCholesterolSelect:
String highCholesterolStr = (String)
adapterView.getSelectedItem();
if (highCholesterolStr.equalsIgnoreCase("YES")){
highCholesterol = 1;
}
else if (highCholesterolStr.equalsIgnoreCase("NO")){
highCholesterol = 0;
}
//Toast.makeText(adapterView.getContext(),
highCholesterolStr,Toast.LENGTH_SHORT);
break;
case R.id.atrialFibrillationSelect:
String AfibStr = (String) adapterView.getSelectedItem();
if (AfibStr.equalsIgnoreCase("YES")){
atrialFibrillation = 1;
}
else if (AfibStr.equalsIgnoreCase("NO")){
atrialFibrillation = 0;
}
// Toast.makeText(adapterView.getContext(),
AfibStr,Toast.LENGTH_SHORT);
break;
case R.id.HBPSpinSelect:
String HBPstr = (String) adapterView.getSelectedItem();
if (HBPstr.equalsIgnoreCase("YES")){
hypertension = 1;
}
else if (HBPstr.equalsIgnoreCase("NO")){
hypertension = 0;
}
//Toast.makeText(adapterView.getContext(),
HBPstring,Toast.LENGTH_SHORT);
break;
case R.id.familialCVDSpin:
String famCVDStr = (String) adapterView.getSelectedItem();
if (famCVDStr.equalsIgnoreCase("YES")){
familialCVD = 1;
}
else if (famCVDStr.equalsIgnoreCase("NO")){
familialCVD = 0;
}
//Toast.makeText(adapterView.getContext(),
famCVDString,Toast.LENGTH_SHORT);
break;
}
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
Here is the class used to output the result:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_lin_risk);
TextView RiskViewLinRisk = findViewById(R.id.RiskViewLinRisk);
float LinRisk = (float) ((-16.13) + (0.119 * age) - (1.333 * sex)
+ (1.502 * married) + (2.619 * smoker) - (0.555 * (tcVal /
hdlVal)) + (0.026 *ldlVal) + (1.952 * highCholesterol) + (2.867
* atrialFibrillation) + (4.272 * hypertension) + (1.957 *
familialCVD));
String LinRiskStr = Float.toString(LinRisk);
RiskViewLinRisk.setText(LinRiskStr);
}
Just to give a bit more context than in the comments, double division in Java can return a NaN which stands for "not a number". This happens when you divide 0.0 by 0.0, but can also happen if you take the square root of a negative number.
Because Java implements the IEEE standard for NaN, it guarantees that NaN is never equal to itself. In fact, the only comparison that returns true is NaN != NaN. There's a very famous puzzle:
float x = //...
if (x != x)
System.out.println("Foo");
The question is "initialize x to a value which guarantees that Foo is printed". The answer is Float.NaN, because NaN is not equal to itself. Also, this is the only value that could work. All other values in Java would not solve this puzzle.
For this reason, a solution used lots of times to identify if a number is NaN is:
public boolean isNan(float x) {
return x != x;
}
(Since Java 8 a method exists in the standard lib to verify if a number is NaN)
You could use this to check the result of the division you're doing and avoid displaying NaN when you don't want to.
To display the values after you click on the button you have to run again the calculation and display it. I recommend extracting it into a method:
public float calculateLinRisk() {
return (float) ((-16.13) + (0.119 * age) - (1.333 * sex)
+ (1.502 * married) + (2.619 * smoker) - (0.555 * (tcVal /
hdlVal)) + (0.026 *ldlVal) + (1.952 * highCholesterol) + (2.867
* atrialFibrillation) + (4.272 * hypertension) + (1.957 *
familialCVD));
}
public void displayCurrentLinRisk() {
// This can also be a field in the main activity to
// avoid multiple calls to findViewById
TextView RiskViewLinRisk = findViewById(R.id.RiskViewLinRisk);
float LinRisk = calculateLinRisk()
String LinRiskStr = Float.toString(LinRisk);
RiskViewLinRisk.setText(LinRiskStr);
}
onCreate becomes:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_lin_risk);
displayCurrentLinRisk();
}
Then you can use this at the end of click listener
BtnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// ...
displayCurrentLinRisk();
}
}
I want to update State list according to the country type in autocompletetextview. I have used the below code .It is working fine for the first time .I write country but once i edit the country name .It is not updating the state list(used notifyDataSetChanged but its not working).Please check the code .Thanks!
AutoCompleteTextView country_edit,state_edit;
for (int i = 1; i < global.getExcel().length; i++) {
String[] separated = global.getExcel()[i].split(",");
code = separated[0]; // this will contain "Fruit"
country = separated[1];
Log.e("length", code + "==" + country);
Log.e("sep", separated + "====" + global.getExcel()[i]);
countrylist.add(country);
codelist.add(code);
Log.e("countrylist", countrylist + "==");
}
//==============================================ArrayAdapter Country & state
final ArrayAdapter<String> country_adapter = new ArrayAdapter<String>
(this, R.layout.custom_autolistview_list, R.id.text1, countrylist);
country_edit.setThreshold(1);
country_edit.setAdapter(country_adapter);
final ArrayAdapter<String> state_adapter = new ArrayAdapter<String>
(this, R.layout.custom_autolistview_list, R.id.text1, State_array);
state_edit.setThreshold(1);
state_edit.setAdapter(state_adapter);
state_edit.setDropDownHeight(WRAP_CONTENT);
state_adapter.notifyDataSetChanged();
country_edit.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Log.e("country", country_edit.getText().toString());
country_str = country_edit.getText().toString();
// Log.e("country", country_str);
int index = countrylist.indexOf(country_str);
Log.e("index", index + "");
String code_index = codelist.get(index);
Log.e("code", code_index);
State_list.clear();
State_array.clear();
for (int i = 0; i < global.getState().length; i++) {
if (global.getState()[i].contains("," + code_index + ",")) {
String statelist = global.getState()[i];
Log.e("statelist", statelist);
State_list.add(statelist);
Log.e("State", State_list + "");
state_name = "";
for (int j = 0; j < State_list.size(); j++) {
String[] statelist_array = State_list.get(j).split(",");
state_name = statelist_array[0];
String state_code = statelist_array[1];
Log.e("state_code", state_code);
Log.e("state_name", state_name);
}
Log.e("Stateeeeeeeee", State_array + "");
State_array.add(state_name);
Log.e("Stateeeeeeeeeeeeeeee", State_array + "");
}
state_ll.setVisibility(View.VISIBLE);
}
state_adapter.notifyDataSetChanged();
}
});
I have two Button + and - when i click on the + button the value increases in the textview and vice versa. but i want to multiply the textview number to the price and change the price accordingly.
viewHolder.mBtnAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PojoCategory pojoCategory = (PojoCategory) v.getTag();
int mValue = pojoCategory.getmQuantity();
mValue++;
viewHolder.tv_Number.setText("" + mValue);
pojoCategory.setmQuantity(mValue);
String value1 = viewHolder.tv_Number.getText().toString();
String value2 = pojoCategory.getDish_rate();
Log.e("value1", value1);
Log.e("value2", value2);
int x = Integer.parseInt(value1);
int y = Integer.parseInt(value2);
int z = x * y;
Log.e("z", "" + z);
viewHolder.Dish_rate.setText(String.valueOf(z));
notifyDataSetChanged();
}
});
I got ListView with simpleAdapter. If I click on some item in my List view it show me 2 diferent variables.
Some code:
// Listview Data
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(Invoice_numberArr.length);
Map<String, Object> m;
for(int i = 0; i<Invoice_numberArr.length; i++){
int str = Integer.parseInt(Invoice_numberArr[i]);
int str2 = Integer.parseInt(InvoiceNumberForDetails);
if(str == str2){
m = new HashMap<String, Object>();
m.put(ATT_INU, Invoice_numberArr[i]);
m.put(ATT_ANU, Article_numberArr[i]);
m.put(ATT_AMO, AmountArr[i]);
m.put(ATT_PRE, PriceArr[i]);
m.put(ATT_TPR, Total_priceArr[i]);
m.put(ATT_SDE, Sale_designationArr[i]);
data.add(m);
}
}
String[] from = {ATT_INU, ATT_ANU, ATT_AMO, ATT_PRE, ATT_TPR, ATT_SDE};
int[] till = {R.id.txtInvoice_number, R.id.txtArticle_number, R.id.txtAmount, R.id.txtPrice, R.id.txtTotalPrice, R.id.txtSale_designation};
//activities elements
invoices_list_details_view = (ListView)findViewById(R.id.invoices_list_details_view);
invoicesDetailsSAdapter = new SimpleAdapter(InvoicesDetails.this, data, R.layout.invoices_list_item_details_view, from , till);
invoices_list_details_view.setAdapter(invoicesDetailsSAdapter);
Utility Utility = new Utility();
Utility.setListViewHeightBasedOnChildren(invoices_list_details_view);
//if item clicked
invoices_list_details_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String positions = parent.getAdapter().getItem(position).toString();
//int positions = parent.getAdapter().;
parent.getAdapter();
int indexPos = -1; // if doesnt exist
for (int i = 0; i < Invoice_numberArr.length; i++) {
if (positions.contains("article_numbers="+Article_numberArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"amounts="+AmountArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"prices="+PriceArr[i]+", "+"total_prices="+Total_priceArr[i])) {
indexPos = i;
break;
} else if (positions.contains("prices="+PriceArr[i]+", "+"article_numbers="+Article_numberArr[i]+", "+"amounts="+AmountArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"total_prices="+Total_priceArr[i])){
indexPos = i;
break;
}
}
//some int to transfer it to position class
int integerr = indexPos;
Intent invoices_details_position = new Intent(InvoicesDetails.this, InvoicesDetailsPosition.class);
invoices_details_position.putExtra("saleDesignationForPosition", Sale_designationArr[indexPos]);
invoices_details_position.putExtra("articleNumberForPosition", Article_numberArr[indexPos]);
invoices_details_position.putExtra("sequenceNumberForPosition", Sequence_numberArr[indexPos]);
invoices_details_position.putExtra("amountForPosition", AmountArr[indexPos]);
invoices_details_position.putExtra("warehouseForPosition", WarehouseArr[indexPos]);
invoices_details_position.putExtra("containerDescriptionForPosition", Container_descriptionArr[indexPos]);
invoices_details_position.putExtra("priceForPosition", PriceArr[indexPos]);
invoices_details_position.putExtra("discountForPosition", DiscountArr[indexPos]);
invoices_details_position.putExtra("totalPriceForPosition", Total_priceArr[indexPos]);
startActivity(invoices_details_position);
}
});
So if clicked on my item from ListView under android 4.3 till 5.0 varible
String positions = parent.getAdapter().getItem(position).toString();
shows me
string " {prices=10.8, article_numbers=0736, amounts=1, sale_designations=Pfirsichlikör, invoice_numbers=1, total_prices=10.8} "
And if I clicked under Android version 5.1 its shows me
string " {article_numbers=0736, sale_designations=Pfirsichlikör, amounts=1, invoice_numbers=1, prices=10.8, total_prices=10.8} "
Because that I need to check it twice with that
for (int i = 0; i < Invoice_numberArr.length; i++) {
if (positions.contains("article_numbers="+Article_numberArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"amounts="+AmountArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"prices="+PriceArr[i]+", "+"total_prices="+Total_priceArr[i])) {
indexPos = i;
break;
} else if (positions.contains("prices="+PriceArr[i]+", "+"article_numbers="+Article_numberArr[i]+", "+"amounts="+AmountArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"total_prices="+Total_priceArr[i])){
indexPos = i;
break;
}
}
So my question now why does it changes depending on Android version ?
Thx for help.
Thank #Mike M. LinkedHashMap s instead HashMap s works for all Android
want to use the the value of variable b in spinner selection. See the code .
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 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 l;
l = 80;
int y;
y = l - age;
c = y + 10;
b = 2016 + c;
editText3.setText(name + (" you might die in year ") + b + "");}}} // this is button code //
now comes the spinner code .
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
final 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);
String disease = spinner1.getSelectedItem().toString();
spinner1.setAdapter(dataAdapter);
if (disease.equals("Diabetes")) {
int x = b-5;
int j = 2016+ x ;
String name = editText.getText().toString();
editText3.setText(name + (" you might die in year ") + j + ""); }
else if (disease.equals("none,i am healthy")) {
String name = editText.getText().toString();
int x = b + 7 ;
int j = 2016 + x ;
editText3.setText(name + ( "you might die in year ") + j + "");
}
};});
};};
this app is executing without an error yet it is not giving me the desired output . How do i use the value of b in spinner ( i have already defined it global)