Creating a searchable contacts kind of app. Below is my code
public class EmployeeList extends Activity {
protected EditText searchText;
protected SQLiteDatabase db;
protected Cursor cursor, listcursor;
protected ListAdapter adapter;
protected ListView employeeList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = (new DatabaseHelper(this)).getWritableDatabase();
searchText = (EditText) findViewById (R.id.searchText);
employeeList = (ListView) findViewById (R.id.list);
listcursor = db.rawQuery("SELECT * FROM employee",null);
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
listcursor,
new String[] {"firstName", "lastName", "title"},
new int[] {R.id.firstName, R.id.lastName, R.id.title});
employeeList.setAdapter(adapter);
}
public void search(View view) {
// || is the concatenation operation in SQLite
cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE firstName || ' ' || lastName LIKE ?",
new String[]{"%" + searchText.getText().toString() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
cursor,
new String[] {"firstName", "lastName", "title"},
new int[] {R.id.firstName, R.id.lastName, R.id.title});
employeeList.setAdapter(adapter);
}
}
The issue is after clearing the word from the edittext. it should go back to previous listview i.e, it should show all values in the db.

Instead of using a second cursor, you should use a FilterQueryProvider with your EditText to update perform multiple updates to the ListView much like an AutoCompleteTextView.
Or you could add a TextWatcher and change the cursor back to your first one whenever the length is becomes zero.