In this article, we are going to create a filterable listview application in Android. Filterable listview means that, whenever user types in some text, correspondingly the items in the listview will be filtered.
1. Create an Android project namely “ListViewFilterable”
2. Select a build target for this application
3. Enter the application details
4. Open and update the file /res/layout/main.xml with the given below code :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
5. Open and update the file /src/in/wptrafficanalyzer/listviewfilterable with the given below code :
package in.wptrafficanalyzer.listviewfilterable; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity { String[] countries = new String[] { "India", "Pakistan", "Sri Lanka", "China", "Bangladesh", "Nepal", "Afghanistan", "North Korea", "South Korea", "Japan" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Creating an array adapter to host the list view items ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries); // Get the reference of listview from the main layout ListView listView = (ListView) findViewById(R.id.listview); listView.setAdapter(adapter); // This statement enables text filtering in the listview listView.setTextFilterEnabled(true); } }
6. Running the application
7. Download the source code

8. Testing this application
Testing of this application is discussed in the article “Testing Filterable ListView in Android”
8. Reference
http://developer.android.com/guide/index.html

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in
You can hire me on hourly basis or on project basis for Android applications development.
For hiring me, please mail your requirements to info@wptrafficanalyzer.in.
My other blogs
store4js.blogspot.com
How are you able to type on the screen? Don’t you need an EditText?
How to do filtering the listview populate with mysal database data having baseAdapter. If you can please help me.