我申请了
安卓我正在使用CursorTreeAdapter作为ExpandableListView.现在我想使用搜索框来显示已过滤的ExpandableListView项.像这样:
这是我到目前为止的代码:
MainActivity.java:
package com.example.cursortreeadaptersearch;
import java.util.HashMap;
import android.app.SearchManager;
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.util.Log;
import android.widget.ExpandableListView;
import android.widget.SearchView;
import android.widget.SearchView.OnCloseListener;
import android.widget.SearchView.OnQueryTextListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class MainActivity extends SherlockFragmentActivity {
private SearchView search;
private MyListAdapter listAdapter;
private ExpandableListView myList;
private final String DEBUG_TAG = getClass().getSimpleName().toString();
/**
* The columns we are interested in from the database
*/
static …Run Code Online (Sandbox Code Playgroud) 下面是我的actvity中的代码以及一个内部类,它是Simple Cursor Tree Adapter的一个子类.问题是当我点击"有错误"的子元素时
protected void onStart() {
super.onStart();
SQLiteDatabase db = new ToDoDatabase(getApplicationContext())
.getWritableDatabase();
Cursor cursor = db.query(true, ToDoDatabase.TABLE_NAME, null, null,
null, null, null, null, null);
CustomCursorTreeAdapter cursorTreeAdapter = new CustomCursorTreeAdapter(
getApplicationContext(), cursor, R.layout.group_item_layout,
new String[] { ToDoDatabase.TASK_NAME_FORMAT_DATE },
new int[] { R.id.groupItem }, R.layout.child_item_layout,
new String[] { ToDoDatabase.TASK_TIME },
new int[] { R.id.childItem });
drawerList.setAdapter(cursorTreeAdapter);
}
public class CustomCursorTreeAdapter extends SimpleCursorTreeAdapter {
public CustomCursorTreeAdapter(Context context, Cursor cursor,
int groupLayout, String[] groupFrom, int[] groupTo,
int childLayout, String[] childFrom, int[] …Run Code Online (Sandbox Code Playgroud)