Check item selected on two spinners? - java

I have two spinners on my layout as below:
public class DemoActivity extends Activity {
private static final String STATE_SCALE = "state-scale";
private static final String STATE_CENTER_X = "state-center-x";
private static final String STATE_CENTER_Y = "state-center-y";
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
String text1 = spinner1.getSelectedItem().toString();
Spinner spinner3 = (Spinner) findViewById(R.id.spinner3);
String text3 = spinner3.getSelectedItem().toString();
if (text1.equals("Harris Academy"))
Harris(spinner1);
if (text1.equals("Harris Academy") && text3.equals("Ground Floor")) {
Toast.makeText(getBaseContext(), text3, Toast.LENGTH_LONG).show();
try {
SubsamplingScaleImageView imageView =
(SubsamplingScaleImageView) findViewById(id.imageView);
imageView.setImageAsset("DSC00277.png");
if (savedInstanceState != null &&
savedInstanceState.containsKey(STATE_SCALE) &&
savedInstanceState.containsKey(STATE_CENTER_X) &&
savedInstanceState.containsKey(STATE_CENTER_Y)) {
imageView.setScaleAndCenter(savedInstanceState.getFloat(STATE_SCALE),
new PointF(savedInstanceState.getFloat(STATE_CENTER_X),
savedInstanceState.getFloat(STATE_CENTER_Y)));
}
} catch (IOException e) {
Log.e(DemoActivity.class.getSimpleName(), "Could not load asset", e);
}
}
}
}
This works fine when the app starts it gets the value of spinner 1 and spinner 3 and then does something depending on the values.
How do I extend it so that when I select an item on either spinner it does something based on the new values?

To get updated value as user select item from spinner,
You have to implement spinner's onItemSelectedListner
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// Do your stuff here for spinner1
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// Do your stuff here for spinner3
}
public void onNothingSelected(AdapterView<?> parent) {
}
});

If you want to manipulate views or data on the selection of item in Spinner you need to implement
ItemSelectedListener to the particular Spinner.
Sample Code:
// in onCreate() or where you want to bind this Views with XML views
{
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner3 = (Spinner) findViewById(R.id.spinner3);
// mItemSelectedListener Object of OnItemSelectedListener to handle Item Selection to Spinners.
spinner1.setOnItemSelectedListener(mItemSelectedListener);
spinner3.setOnItemSelectedListener(mItemSelectedListener);
}
// Creating an Object of Anonymous Class so no need to create another instance for same class
// OutSide of onCreate() method.
OnItemSelectedListener mItemSelectedListener = new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (view.getId()) {
case R.id.spinner1:
// Manipulates Views at selection of item in Spinner1
break;
case R.id.spinner3:
// Manipulates Views at selection of item in Spinner3
break;
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {}
};

Related

Get the String value from Second spinner position

I have two spinner.
First spinner value is Kathmandu and Bhaktapur and depending on first spinner value, second spinner value is filled up.
My problem is when I select Kathmandu and select first item from second spinner I get the first item of second spinner which is what i expect.
But when I select Bhaktapur or any item below Kathmandu from Spinner first, Then on Selecting first item position from second spinner I get first spinner value itself which Is Bhaktapur instead of "Bageswori"
But if I select second item position then there is no problem i.e I get the "Balkot" which is expected outcome.
So problem lies when I select any item below first item position from First spinner and first item position form second spinner.It returns first item value of First spinner instead of selected value from Second spinner.
My Code is
public class UploadBook extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
String item = "start";
String condition = "start"; // for spinner
FirebaseStorage storage;
public Books b;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_book);
getSupportActionBar().setTitle("Upload Room Info");
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#8abe50")));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)
ActivityCompat.requestPermissions(UploadBook.this, new String[]{android.Manifest.permission.CAMERA, android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 11);
database = FirebaseDatabase.getInstance();
dbreference = database.getReference();
fauth = FirebaseAuth.getInstance();
mStorageRef = FirebaseStorage.getInstance().getReference();
b1 = (Button) findViewById(R.id.buttonPost);
spinnerCountry = (Spinner) findViewById(R.id.spinnerCountry);
//implementing OnItemSelectedListener (need to override the method)
countryArray = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
countryArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCountry.setAdapter(countryArray);
countryArray.add("Kathmandu");
countryArray.add("Bhaktapur");
countryArray.add("Lalitpur");
countryArray.setNotifyOnChange(true);
spinnerCountry.setSelection(0);
spinnerDivision = (Spinner) findViewById(R.id.spinnerDivision);
//implementing OnItemSelectedListener (need to override the method)
spinnerDivision.setOnItemSelectedListener(this);
spinnerCountry.setOnItemSelectedListener(this);
divisionArray = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
divisionArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDivision.setAdapter(divisionArray);
postButtonClick();
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
item = parent.getItemAtPosition(position).toString();
//first spinner item position
int countrySpinnerPosition = spinnerCountry.getSelectedItemPosition();
switch (countrySpinnerPosition){
case 0:
//fill data for second spinner
fillKathmanduDivision();
break;
case 1:
//fill data for second spinner
fillBhaktapurDivision();
break;
}
//first spinner item position
}
private void fillKathmanduDivision() {
divisionArray.clear();
divisionArray.add("Anamnagar");
divisionArray.add("Balaju");
divisionArray.notifyDataSetChanged();
}
private void fillBhaktapurDivision() {
divisionArray.clear();
divisionArray.add("Bageswori");
divisionArray.add("Balkot");
divisionArray.notifyDataSetChanged();
}
b1.setOnClickListener(new View.OnClickListener() {
}
void postButtonClick() {
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(this, item, Toast.LENGTH_SHORT).show();
}
}
}
Please use this code below :
private String country_id = "", city_id = "";
private ArrayList<String> country_array;
and to fill your array with data :
for (int i = 0; i < items.getResponse().size(); i++) {
String get_country_name = items.getResponse().get(i).getCode();
country_array.add(get_country_name);
}
Now for your first spinner adapter :
ArrayAdapter<String> country_spinnerArrayAdapter = new adapter_spinner(getActivity(), R.layout.spinner_header, country_array);
country_spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item);
binding.etCountry.setAdapter(country_spinnerArrayAdapter);
binding.etCountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedItemText = parent.getSelectedItem().toString();
if (position > 0) {
country_id = selectedItemText;
city_id = "";
Load_City(position - 1); // -1 to remove postion of the static country text
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Now your City (2nd spinner) method :
private void Load_City(int postion) {
ArrayList<String> city_array = new ArrayList<String>();
city_array.add(getString(R.string.city));
for (int i = 0; i < items.getResponse().get(postion).getCities().size(); i++) {
String get_city_name = items.getResponse().get(postion).getCities().get(i).getName();
city_array.add(get_city_name);
}
ArrayAdapter<String> country_spinnerArrayAdapter = new adapter_spinner(getActivity(), R.layout.spinner_header, city_array);
country_spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item);
binding.etCity.setAdapter(country_spinnerArrayAdapter);
binding.etCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedItemText = parent.getSelectedItem().toString();
if (position > 0) {
city_id = selectedItemText;
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
i hope this helped
You have taken wrong reference of first spinner.
in below line
int countrySpinnerPosition = spinnerCountry.getSelectedItemPosition();
you have taken spinnerCountry instead of spinnerFirst.
And you have initially set spinnerFirst to first postion that is A and When you change it-to select B its value not taken in onItemSelected method ,intend of takes country selected that is probably on first (0) position of spinner so you second spinner always set to Three instead of Four.

Unable to get Second Spinner value based on first Spinner Value

I'm using Two Spinners where Second Spinner Value is based on First Spinner Value.
For Example If user Select Option A in First Spinner Then Second Spinner drop down list must contain value ( ox, cow, goat ) and if user select option B, then second Spinner value must contain ( Lion, Tiger and Cheetha ).
But I'm unable to do so. On selecting any value in first spinner value, Second Spinner always loads same value. Below is the screenshot
As you can see, In selecting any option in first spinner master or diploma...In second spinner value is same.it does not change.
Below is my Activity Code
public class UploadBook extends AppCompatActivity
Spinner spinnerCountry,spinnerDivision,spinner_condition;
ArrayAdapter<String> countryArray,divisionArray;
String item = "start";
int count = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_book);
getSupportActionBar().setTitle("Upload book");
spinnerCountry = (Spinner) findViewById(R.id.spinnerCountry);
//implementing OnItemSelectedListener (need to override the method)
spinnerCountry.setOnItemSelectedListener(this);
countryArray = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
countryArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCountry.setAdapter(countryArray);
countryArray.add("Master");
countryArray.add("Diploma");
countryArray.setNotifyOnChange(true);
spinnerCountry.setSelection(0);
spinnerDivision = (Spinner) findViewById(R.id.spinnerDivision);
//implementing OnItemSelectedListener (need to override the method)
spinnerDivision.setOnItemSelectedListener(this);
divisionArray = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
divisionArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDivision.setAdapter(divisionArray);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
item = parent.getItemAtPosition(position).toString();
count = position;
//first spinner item position
int countrySpinnerPosition = spinnerCountry.getSelectedItemPosition();
switch (countrySpinnerPosition){
case 1:
//fill data for second spinner
fillMasterDivision();
break;
case 2:
//fill data for second spinner
fillDiplomaDivision();
break;
}
}
private void fillMasterDivision() {
divisionArray.clear();
divisionArray.add("Select Subject:-");
divisionArray.add("MSC Physics");
divisionArray.add("MSC Chemistry");
divisionArray.notifyDataSetChanged();
}
private void fillDiplomaDivision() {
divisionArray.add("Select Subject:-");
divisionArray.add("Science");
divisionArray.add("CTEVT");
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
Please Help.
There is two mistake in your code.
CountrySpinnerPosition will be 0 and 1 for your case so the case should be "case 0" and "case 1".
In fillDiplomaDivision method, you have to first clear the list and after adding into the list you have to call notifyDataSetChanged().
try to clear the arraylist and notifydatasetchanged in second method too
private void fillDiplomaDivision() {
divisionArray.clear();
divisionArray.add("Select Subject:-");
divisionArray.add("Science");
divisionArray.add("CTEVT");
divisionArray.notifyDataSetChanged();
}
First of all ,you are using same onItemSelected for both the spinner . so remove spinnerCountry.setOnItemSelectedListener(this); and spinnerDivision.setOnItemSelectedListener(this);
After setting data to spinnerCountry use this .
spinnerCountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if(i == 0){
fillMasterDivision();
}else{
fillBachelorDivision();
}
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
and clear your Division array in fillBachelorDivision()
See my example:
I have 2 spinners, firstSpinner and secndSpinner, Second depends of First.
First you have to initialize the spinners in onCreate method, and follow steps:
1 - You'll insert in first spinner your data ("Master", "Diploma");
2 - You'll create a function that will update the second spinner with associated values.
firstSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
createSecondSpinnerByFirst(position);
}
#Override
public void onNothingSelected(AdapterView<?> adapter) {
}
});
private void createSecondSpinnerByFirst(Integer position) {
List<String> secValues = new ArrayList<>();
switch (position) {
case 1:
// insert in secValues array the strings of this condition
break;
case 2:
// insert in secValues array the strings of this condition
break;
}
// usually I use Adapter
final SpinnerAdapter adapter = new SpinnerAdapter(this, secValues);
secndSpinner.setAdapter(adapter);
}
//Code of myAdapter
public class SpinnerAdapter extends ArrayAdapter<String> {
private Context context;
private List<String> mValues;
public SpinnerAdapter(Context ctx, List<String> values) {
super(ctx, 0, values);
context = ctx;
mValues = values;
}
#Override
public int getCount() {
return mValues.size();
}
#Override
public Process getItem(int position) {
return mValues.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return returnLayoutSpinner(context, convertView, mValues.get(position));
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return returnLayoutSpinner(context, convertView, mValues.get(position));
}
}
//My function to return the adapter view
private View returnLayoutSpinner(Context context, View convertView, String value) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.spinner_items_view, null);
}
TextView txt = convertView.findViewById(R.id.txtSpinnerItem);
txt.setText(value, 25);
return convertView;
}
//spinner_items_view.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txtSpinnerItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|left"
android:padding="13dp"
android:textColor="#android:color/black"
android:textSize="16sp">
</TextView>
private void fillDiplomaDivision() {
//add this line in your code and it solve
divisionArray.clear();
divisionArray.add("Select Subject:-");
divisionArray.add("Science");
divisionArray.add("CTEVT");
}

Spinner: getItemAtPosition(position) is returning always null/empty

I wanted to display selected item in the textView when selected from dropdown list of spinner I implemented AdapterView.OnItemSelectedListener but when I'm selecting item its always null/empty here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(new CustomAdapter(MainActivity.this, Languages));
btn.setOnClickListener(this);
spinner.setOnItemSelectedListener(this);
}
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
item = (String)parent.getItemAtPosition(position);
Toast.makeText(MainActivity.this, item.toString(),
Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
SO answer source: https://stackoverflow.com/a/49301966/5461982
I know this is an older question now but if anyone else comes across it be sure to check that your custom implementation of the Adapter you're setting for your Spinner overrides the getItem method:
#Override
public Object getItem(int position) {
return spinnerItems.get(position);
}
By default, you're required to override this method when implementing a custom BaseAdapter but the default return type is null. Be sure to modify the return type to return spinnerItems.get(position).
Hope this helps, I spent around 30 mins trying to work this out originally!
Try this,
String selected_item = spinner.getSelectedItem().toString();
Just retrieve value from String Array:
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final String item = Languages[position];
Toast.makeText(MainActivity.this, item, Toast.LENGTH_SHORT).show();
}
try this
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
sSelectedItem = arr_spiner.get(spinner.getSelectedItemPosition())
.getName();
txtSpinnerValue.setText(sSelectedItem);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
https://stackoverflow.com/questions/45159011/spinner-item-is-not-visible-data-is-coming-from-server-android/45161202#45161202
Try This
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(new CustomAdapter(MainActivity.this, Languages));
btn.setOnClickListener(this);
spinner.setOnItemSelectedListener(this);
}
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
//item = (String)parent.getItemAtPosition(position);
item = (String) spinner.getSelectedItem().toString(); //Here is the Change
Toast.makeText(MainActivity.this, item.toString(),
Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
The change here is
From
item = (String)parent.getItemAtPosition(position);
TO
item = (String) spinner.getSelectedItem().toString();

Spinner Value to String

Been making my first app and slow progress is being made. Just wondering how I return a Spinner value to pass it as a string.
Here is my code:
First the event class:
public void event(){
calanderBtn = (Button)findViewById(R.id.eventBtn);
calanderBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.Events.TITLE, "Home");
intent.putExtra(CalendarContract.Events.DESCRIPTION, "Cleaning : ");
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "Home");
startActivity(intent);
}
});
}
Second the Spinner Class:
public void selectcleaning() {
spCleaning = (Spinner) findViewById(spinner);
adapterCleaningType = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, cleaningType);
adapterCleaningType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spCleaning.setAdapter(adapterCleaningType);
}
I'm trying to select the value from selectcleaning (Value is either Yes or No) and pass it in the descrption in the Calendar of the event class and I'm not sure what to do.
you can use this code to get the value
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
or get the value when spinner selected using OnItemSelectedListener (Android Doc)
public class SpinnerActivity extends Activity implements
OnItemSelectedListener {
#Override
protected void onStart() {
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
}
You should try using the Overrides for the spinner class as so:
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
}});
For your purposes 'int position' would equal 0 (yes) or 1 (no)
Try setting an on item selected listener. When an item is selected, you can store that value in a global variable. It gets the first item by default too.
spCleaning.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// Value is current spinner item
globalStringVariable = (String) parent.getItemAtPosition(position);
}
// Because AdapterView is an abstract class, onNothingSelected must be defined
#Override
public void onNothingSelected(AdapterView<?> parent) {
// This is default, before you've selected anything.
// It gets the first value.
globalStringVariable = parent.getItemAtPositon(0);
}
});

How can I sum multiple spinners?

I have multiple spinners with a string array that has 3 items called "70","80" and "90". After the user selects these different spinner items I want to be able to sum up all of the items which the user has selected and display the total in a textview.For example a user selects "70" from one spinner and "70" from another, a textview will show the total 140. How can I do this?
public class FragmentCalc3 extends Fragment{
Context context;
TextView Results;
public static FragmentCalc3 newInstance()
{
FragmentCalc3 fragment = new FragmentCalc3();
return fragment;
}
public FragmentCalc3() {}
// Required empty public constructor
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_calculator3, container, false);
Results = (TextView) rootView.findViewById(R.id.Results);
context = container.getContext();
final Spinner spinner1 = (Spinner) rootView.findViewById(R.id.TestSpinner2);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(context, R.array.GradeTest, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Specify the layout to use when the list of choices appears
spinner1.setAdapter(adapter1); // Apply the adapter to the spinner
final Spinner spinner2 = (Spinner) rootView.findViewById(R.id.TestSpinner1);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(context, R.array.GradeTest, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Specify the layout to use when the list of choices appears
spinner2.setAdapter(adapter2); // Apply the adapter to the spinner
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int spinner2Value = Integer.parseInt(spinner2.getSelectedItem().toString());
int spinner1Value = Integer.parseInt(spinner1.getSelectedItem().toString());
int Results = spinner2Value + spinner1Value;
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
return rootView;
}
}
If you have two spinners spinner2 and spinner1, And you want to get result when item of spinner2 is selected then simply do like this,
spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
int spinner2Value = Integer.parseInt(spinner2.getSelectedItem().toString()); //Add try catch block if necessary
int spinner1Value = Integer.parseInt(spinner1.getSelectedItem().toString());
int yourResult = spinner2Value + spinner1Value; //Result
}
#Override
public void onNothingSelected(AdapterView<?> parentView) {
//Do nothing
}
});

Categories