Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Android
How to validate a spinner in android
Satchidananda Mohanty
Ranch Hand
Posts: 78
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello,
I want to validate a spinner value. But I do not want to select or click on the spinner. My code is like this.
Spinner s = (Spinner) findViewById(R.id.poltype); s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView adapter, View v, int i, long lng) { pol_type = adapter.getItemAtPosition(i).toString(); } @Override public void onNothingSelected(AdapterView arg0) { Toast.makeText(MyActivity.this,"Please Select the policy type !!", Toast.LENGTH_LONG).show(); return; } }); if(pol_type.equalsIgnoreCase("Choose policy") || pol_type.equals("")){ Toast.makeText(MyActivity.this,Please Select the policy type !!", Toast.LENGTH_LONG) .show(); return; }
This code does not work, Please suggest any solution if you have.
Thanks in advance.
Zeet
SCJP 6.0
Satchidananda Mohanty
Ranch Hand
Posts: 78
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Found the solution.
Spinner poltype = (Spinner) findViewById(R.id.poltype); String st =poltype.getSelectedItem().toString(); int pos =poltype.getSelectedItemPosition(); if(pos!=0) { pol_type = poltype.getSelectedItem().toString(); } else{ Toast.makeText(MyActivity.this, "Please Select the policy type !!", Toast.LENGTH_LONG) .show(); return; } if(!st.equals("Choose policy")) { pol_type = poltype.getSelectedItem().toString(); } else{ Toast.makeText(MyActivity.this, "Please Select the policy type !!", Toast.LENGTH_LONG) .show(); return; }
Zeet
SCJP 6.0
Hussein Baghdadi
clojure forum advocate
Posts: 3479
I like...
posted 13 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks for sharing it
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Doubt with ArrayAdapter,ArrayAdapterView
Android Studio and Java calling a button press variable
Using Spinner Values
how to change the array into an file
Arraylist keeps overwriting the last entry i added
More...