java - How to compare two spinner values to display toast & change one spinner value -
i want display toast when 2 spinner values same, , revert spinner1 value default value being same spinner two
here java code
package com.test16.sp2; import android.app.activity; import android.os.bundle; import android.view.*; import android.widget.*; import android.widget.adapterview.onitemselectedlistener; public class test16sp2activity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); spinner spin1=(spinner)findviewbyid(r.id.spinner1); spinner spin2=(spinner)findviewbyid(r.id.spinner2); arrayadapter<charsequence> adapter1= arrayadapter.createfromresource(this, r.array.planet_array1, android.r.layout.simple_spinner_item); arrayadapter<charsequence> adapter2= arrayadapter.createfromresource(this, r.array.planet_array2, android.r.layout.simple_spinner_item); adapter1.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); adapter2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spin1.setadapter(adapter1); spin2.setadapter(adapter2); spin1.setonitemselectedlistener(new myonitemselectedlistener()); spin2.setonitemselectedlistener(new myonitemselectedlistener()); } public class myonitemselectedlistener implements onitemselectedlistener { spinner spin1=(spinner)findviewbyid(r.id.spinner1); spinner spin2=(spinner)findviewbyid(r.id.spinner2); public void onitemselected(adapterview<?> parent, view view, int pos, long id) { if(spin1==spin2) { toast.maketext(parent.getcontext(), "your source , destination same", toast.length_long).show(); } } public void onnothingselected(adapterview<?> parent) { // nothing. } } }
rest files same android developer's planet example http://developer.android.com/resources/tutorials/views/hello-spinner.html
you comparing spinners, not spinner values. @ properties of spin1
, spin2
variables, should find along lines of .getselected()
Comments
Post a Comment