Amigos, gostaria de saber se é possível criar um filtro na ListView. Eu tenho um editText ou AutoComplete, não sei qual é mais indicado para esse caso, e ao digitar uma letra no campo ele filtrasse na ListView, mostrando os dados com as iniciais digitadas no campo. Os dados vem de um SQLite. Utilizo DAO.
Carrego a lista assim:
// Carrega dados para a lista
ClienteDAO dao = new ClienteDAO(getBaseContext());
setListAdapter(new ClienteAdapter(getBaseContext(), dao.getAll()));
Eu fiz assim:
private TextWatcher filterTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
ClienteDAO dao = new ClienteDAO(getBaseContext());
setListAdapter(new ClienteAdapter(getBaseContext(), dao.getAll()));
setListAdapter(adapter.)
}
};
XML da lista:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/ltvDados"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</ListView>
<Button
android:id="@+id/btnApagar"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="Apagar_click"
android:text="Apagar" />
</RelativeLayout>