gpt4 book ai didi

java - relativeLayout 无法转换为 android.text.TextWatcher

转载 作者:行者123 更新时间:2023-12-02 11:45:01 25 4
gpt4 key购买 nike

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

<小时/>

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

public void autoSearch(View view) {
//auto search complete for comunity list
this.context = context;

String array1[] = firebaseComunityListArr.toArray(new String[firebaseComunityListArr.size()]);
AutoCompleteTextView txt = (AutoCompleteTextView) view.findViewById(R.id.myAutoComplete);
txt.addTextChangedListener((TextWatcher) getView());
txt.setAdapter(new ArrayAdapter<String>(getContext(), android.R.layout.simple_dropdown_item_1line, array1));
txt.setTextColor(Color.GREEN);
txt.setAdapter(adapter);
}


@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(Editable editable) {

}

这是 xml

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

最佳答案

据我了解,您需要像这样实现 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"/>

关于java - relativeLayout 无法转换为 android.text.TextWatcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48281360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com