Hello, Let's see the above example for your awesome dropdown list to search. Searchable Spinner is a dialog spinner with the search feature which allows you to search the items loaded in the spinner.
You have to use this Gradle library:
com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1
And, your calling should be like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.legendblogs.asynctask.MainActivity">
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="@+id/searchablespinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
In your MainActivity.java:
package com.legendblogs.demo;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> searchablespinner_list = new ArrayList<String>();
SearchableSpinner searchablespinner = (SearchableSpinner) findViewById(R.id.searchablespinner);
searchablespinner_list.add("Samsung");
searchablespinner_list.add("Nokia");
searchablespinner_list.add("Moto");
searchablespinner_list.add("Google");
searchablespinner_list.add("HTC");
searchablespinner_list.add("Leveno");
searchablespinner_list.add("Dell");
searchablespinner_list.add("Oppo");
searchablespinner_list.add("Micromax");
searchablespinner_list.add("Lg");
searchablespinner_list.add("Oppo");
searchablespinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, searchablespinner_list));
}
}
Write a comment