RelativeLayout无法强制转换为android.text.TextWatcher

时间:2018-01-16 12:31:09

标签: java android

我正在尝试进行自动完成,包括能够从firebase数据列表中搜索我搜索的选项

RelativeLayout无法转换为android.text.TextWatcher - 这是我的错误

<?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" >

    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textAutoComplete|textAutoCorrect"
        android:imeOptions="actionSearch"
        android:hint="search here"
        android:id="@+id/myAutoComplete"/>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/my_recycler_view"
        />



</RelativeLayout >

这是xml

Map<Integer, List<String>>

1 个答案:

答案 0 :(得分:1)

根据我的理解,你需要像这样实现TextWatcher

txt.addTextChangedListener(new TextWatcher() {

   @Override
   public void afterTextChanged(Editable s) {}

   @Override    
   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   @Override    
   public void onTextChanged(CharSequence s, int start,
     int before, int count) {

   }
  });

您已经实现了textWatcher

更改此

txt.addTextChangedListener((TextWatcher) getView()); 

txt.addTextChangedListener(this); 

更新

layout_below属性添加到您的recyclerview

<android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/my_recycler_view"
        android:layout_below="@+id/myAutoComplete"/>