Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open SearchableSpinner programmatically

I use SearchableSpinner widget, it is a great spinner, but there is a problem when I want to open the spinner by clicking on a button.

I used performClick() but instead of showing the searchable dialog, the standard one shows up, the searchable dialog appears only if the user clicks on the spinner, I also tried callOnClick() and didn't work.

Searchable Dialog:

enter image description here

Standard Spinner:

enter image description here

like image 640
tinyCoder Avatar asked Jan 31 '26 21:01

tinyCoder


1 Answers

Try this:

yourSearchableSpinner.onTouch(view, MotionEvent.obtain(1, 1, MotionEvent.ACTION_UP, 1, 1, 1));

In fragment, you can get view as:

View view;

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    this.view = view;
    ...
}

In activity, you can get view as:

View view;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout);
    view = findViewById(R.id.your_root_view);
    ...
}
like image 180
Ashwin Avatar answered Feb 03 '26 09:02

Ashwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!