当我尝试在操作栏搜索视图中键入文本时,一旦在操作栏搜索视图中找不到该项目作为文本,键盘将关闭,直到活动暂停后才会再次打开。恢复活动后,键盘将打开
这是我的代码
此方法用于过滤回收站视图
public void callFilter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
mData = new ArrayList<>();
if (charText.length()==0)
{
mData.addAll(mAllData);
}
else {
for (PurchaseDetails item : mAllData) {
if (item.getProd_nm().toLowerCase(Locale.getDefault()).startsWith(charText)|item.getBillNo().toLowerCase(Locale.getDefault()).startsWith(charText)|item.getUserNm().toLowerCase(Locale.getDefault()).startsWith(charText)|item.getPur_Date().toLowerCase(Locale.getDefault()).startsWith(charText)|item.getPur_Qty().toLowerCase(Locale.getDefault()).startsWith(charText)) {
mData.add(item);
}
}
}
notifyDataSetChanged();
}
OnQueryTextChange方法
public boolean onQueryTextChange(String newText)
{
searchText=newText;
myAdapter.callFilter(newText);
return true;
}
这是我的活动布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".purchase.ViewPurchaseActivity">
<android.support.v7.widget.RecyclerView
android:layout_below="@id/linearLayout1"
android:layout_margin="10dp"
android:id="@+id/recyclerViewForAllPurchases"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<RelativeLayout
android:id="@+id/relativeForProgress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa000000"
android:visibility="gone">
<ProgressBar
android:id="@+id/progressbar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>