在我的应用程序中,我从手机联系人列表中获得Arraylist
简单ListView
,并且我在输入edittext
后尝试过滤它。
我在应用程序中使用了viewpages v4,我的EditText
位于ActivityMain
而我的Listview
位于ContactsFragment
ViewPager中,我定义了简单的接口侦听器来发送类型字符ActivityMain
至ContactsFragment
。输入edittext
后ListView
我的softkeyboard
成功按类型字符过滤,但在adapter.getFilter().filter("a");
可见之前不会刷新,我必须要隐藏键盘以通过过滤的字符串刷新列表视图。
例如:
按“a”过滤列表视图:
public class AdapterContacts extends BaseAdapter implements Filterable {
private LayoutInflater inflater;
private Context context;
private List<ContactLists> categoryArrayList;
private final ArrayList<ContactLists> originalList = new ArrayList<ContactLists>();
private NameFilter filter;
public AdapterContacts(ArrayList<ContactLists> array) {
categoryArrayList = array;
}
public AdapterContacts(Context context, List<ContactLists> array) {
this.context = context;
inflater = LayoutInflater.from(this.context);
categoryArrayList = array;
originalList.addAll(array);
}
@Override
public int getCount() {
return categoryArrayList.size();
}
@Override
public ContactLists getItem(int position) {
return categoryArrayList.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
}
private static class UI extends HelperUI {
...
}
private class ViewHolder {
private UI UI;
public ViewHolder(View view) {
UI = new UI(view);
}
public void fillItems(final AdapterContacts adapter, final ContactLists item, final int position) {
...
}
@Override
public Filter getFilter() {
if (filter == null) {
filter = new NameFilter();
}
return filter;
}
private class NameFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
constraint = constraint.toString().toLowerCase();
FilterResults result = new FilterResults();
if (constraint != null && constraint.toString().length() > 0) {
ArrayList<ContactLists> filteredItems = new ArrayList<ContactLists>();
int l = originalList.size();
for (int i = 0 ; i < l; i++) {
ContactLists nameList = originalList.get(i);
if (nameList.getContact_name().toString().contains(constraint)) {
filteredItems.add(nameList);
}
}
result.count = filteredItems.size();
result.values = filteredItems;
} else {
synchronized (this) {
result.values = originalList;
result.count = originalList.size();
}
}
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
ArrayList<ContactLists> temp = (ArrayList<ContactLists>) results.values;
categoryArrayList.clear();
categoryArrayList.addAll(temp);
notifyDataSetChanged();
temp.clear();
notifyDataSetInvalidated();
}
}
}
我的适配器来自Filterable
var fullOutputPath = "~/Content/img/";
var imageBytes = Convert.FromBase64String(str.Replace("data:image/png;base64,", "").Replace("data:image/jpeg;base64,", ""));
using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
ms.Write(imageBytes, 0, imageBytes.Length);
var image = Image.FromStream(ms);
image.Save(fullOutputPath, ImageFormat.Png);
}
答案 0 :(得分:0)
您可以使用以下代码隐藏您的softKeyboard
private void hideKeyboard() {
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) this
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
答案 1 :(得分:-1)
尝试在清单活动声明中使用android:windowSoftInputMode =“adjustPan”