Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 向listview添加搜索功能_Android_Android Listview - Fatal编程技术网

Android 向listview添加搜索功能

Android 向listview添加搜索功能,android,android-listview,Android,Android Listview,我已经在滑动抽屉中创建了用户安装的应用程序的列表视图,我想在其中添加搜索功能。我正在学习教程 到目前为止,这是我的编码(其中包括到目前为止实现的搜索功能): 拖放App.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

我已经在滑动抽屉中创建了用户安装的应用程序的列表视图,我想在其中添加搜索功能。我正在学习教程

到目前为止,这是我的编码(其中包括到目前为止实现的搜索功能): 拖放App.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<SlidingDrawer
    android:id="@+id/bottom"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:orientation="horizontal"
    android:layout_marginTop="200dp"
    android:content="@+id/content"
    android:handle="@+id/handle" >

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Handle" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:orientation="vertical"
        android:background="#00FF00">

            <!-- Editext for Search -->
<EditText android:id="@+id/inputSearch"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Search applications.."
    android:inputType="textVisiblePassword"/>

<ListView
    android:id="@+id/lvApps"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"       
/>


    </LinearLayout>
</SlidingDrawer>

</RelativeLayout>
我不确定该将此编码放在何处:

inputSearch.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
    // When user changed the Text
    MainActivity.this.adapter.getFilter().filter(cs);   
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
        int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable arg0) {
    // TODO Auto-generated method stub                          
}
});

如果您需要查看我的任何其他编码(如应用程序列表视图的任何适配器),请告诉我

这是您的完整代码吗?
inputSearch=(EditText)findviewbyd(R.id.inputSearch)行下方
inputSearch.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
    // When user changed the Text
    MainActivity.this.adapter.getFilter().filter(cs);   
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
        int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable arg0) {
    // TODO Auto-generated method stub                          
}
});