michaelprimez / searchablespinner

Searchable Spinner
Apache License 2.0
314 stars 102 forks source link

How to set items when spinner is loaded? #19

Closed arunarajput closed 6 years ago

arunarajput commented 6 years ago

Currently when I click on spinner icon then respective list is showing but when spinner is loaded so spinner list items are showing only when click on spinner but i want to show as default value on visible items means 0th postion. Actually it is showing blank. Please help me how to replace "Touch to select" text to list items???

michaelprimez commented 6 years ago

I am not sure what exactly you want to do :( but if you want to replace the "Touch to select" with some other text you can use the RevealEmptyText property in your xml.

app:RevealEmptyText="Touch to select"

Also, if you want to replace the Search hint you can use the SearchHintText property

app:SearchHintText="Search Hint Text"

Otherwise, please give me an example of what exactly the "Touch to select" should be replaced.

michaelprimez commented 6 years ago

Then, you can use the

mSearchableSpinner.setSelectedItem(0);

or

mSearchableSpinner.setSelectedItem(1);

if in your adapter you have "No Selection" in the first place.

arunarajput commented 6 years ago

Before setAdapter or after setAdapter ? Which one is correct?

I have another one query is when activity or fragment is loaded then onItemSelected() method not populated the items and position of the items As in spinner onItemSelected() calls everytime when activity or fragment is loaded.

michaelprimez commented 6 years ago

After set adapter. otherwise the spinner doesn't have any item to show.

arunarajput commented 6 years ago

correct...Thanks..Can you please answer the second query? Whenever activity or fragment is loaded so onItemSelected() should be call everytime.

michaelprimez commented 6 years ago

This has to do with how Android/Spinner works. Also simple Android spinner have this behavior, the onItemSelected runs on Activity/Fragments load.

arunarajput commented 6 years ago

so this behavior is not available in this library? How can I achieve this using this library?

michaelprimez commented 6 years ago

It's not library specific. You can find a lot of references on StackOverflow about how you can prevent the Android/Spinner onItemSelected to run when Activity/Fragment is loaded.

Thanks that using the library.

arunarajput commented 6 years ago

When I use android spinner then setOnItemSelectedListener() being called but when I use your searchable spinner then setOnItemSelectedListener() not called. what is the problem?

arunarajput commented 6 years ago

Is there any solution?

michaelprimez commented 6 years ago

There isn't any problem, I don't use any Spinner in the library so when you register a listener you actually register a listener to a ListView witch it has different behavior. If you want to do anything when the Activity/Fragment starts, you can do it inside onCreate/onResume using Searchable Spinner methods.

arunarajput commented 6 years ago

I mean when I use your searchable spinner so setOnItemSelectedListener() not being called. by default the setOnItemSelectedListener() should be call when spinner loaded means we can Toast 0th items also on spinner loaded.

<gr.escsoft.michaelprimez.searchablespinner.SearchableSpinner android:id="@+id/SearchableSpinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:layout_marginLeft="24dp" android:layout_marginRight="24dp" android:layout_marginStart="24dp" android:layout_marginEnd="24dp" android:gravity="center_horizontal" app:ShowBorders="true" app:BordersSize="1dp" app:RevealEmptyText="Touch to select" app:BoarderColor="@color/colorPrimary" app:SpinnerExpandHeight="250dp"/>