好了,所以,我有以下的ListView适配器:过滤的ListView与搜索查看
ListViewAdapter.java
public class ListViewAdapter extends CursorAdapter{
public ListViewAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.listitem, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Find fields to populate in inflated template
Button btnList = (Button) view.findViewById(R.id.btnList);
// Populate fields with cursor
btnList.setText(cursor.getString(0));
}
}
这里是我的充气XML:
列表项。 xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btnList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_item"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"/>
然后我使用它在这里给ListView的光标的内容:
MainActivity.java
ListViewAdapter lvAdapter = new ListViewAdapter(this, cursor);
listView.setAdapter(lvAdapter);
现在,如何将一个用搜索查看过滤的ListView每次我改变searchView文本? (像onTextChange什么的)?
我想出这个至今:
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
todoAdapter.getFilter().filter(newText);
return true;
}
});
但它不会做任何事......如果您需要任何更多信息,随意问:)
我的布局: