Autocompletetextview返回的非空参数为空。
创始人
2024-09-22 20:00:30
0

问题描述:Autocompletetextview返回的非空参数为空。

解决方法:

  1. 检查数据源:首先确保你提供给Autocompletetextview的数据源是正确的。确认数据源中包含非空的参数。
String[] data = {"Apple", "Banana", "Cherry"};
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data);
AutocompleteTextView autocompleteTextView = findViewById(R.id.autocompleteTextView);
autocompleteTextView.setAdapter(adapter);
  1. 检查过滤器:如果你使用了自定义过滤器,确保过滤器的逻辑正确。过滤器应该根据输入的文本来返回匹配的结果。
autocompleteTextView.setThreshold(1); // 设置输入多少个字符后开始过滤,默认为2个字符
autocompleteTextView.setFilter(new Filter() {
    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
        FilterResults filterResults = new FilterResults();
        ArrayList tempList = new ArrayList<>();
        // 执行过滤逻辑,并将结果存储在tempList中
        for (String item : data) {
            if (item.toLowerCase().startsWith(constraint.toString().toLowerCase())) {
                tempList.add(item);
            }
        }
        filterResults.values = tempList;
        filterResults.count = tempList.size();
        return filterResults;
    }

    @Override
    protected void publishResults(CharSequence constraint, FilterResults results) {
        if (results != null && results.count > 0) {
            // 更新Autocompletetextview的数据源
            adapter.clear();
            adapter.addAll((ArrayList) results.values);
            adapter.notifyDataSetChanged();
        } else {
            autocompleteTextView.setText(""); // 清空Autocompletetextview的文本
        }
    }
});
  1. 检查文本输入监听器:如果你在Autocompletetextview上设置了文本输入监听器,确保在监听器中正确处理非空参数为空的情况。
autocompleteTextView.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

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

    @Override
    public void afterTextChanged(Editable s) {
        if (s.toString().isEmpty()) {
            // 处理非空参数为空的情况
        }
    }
});

通过以上方法,你可以解决Autocompletetextview返回的非空参数为空的问题。请根据实际情况选择适用的解决方法。

相关内容

热门资讯

有玩家发现!hhpoker脚本... 有玩家发现!hhpoker脚本,wepoker安装教程(透视)解密教程(有挂详细)-哔哩哔哩1、点击...
透视有挂!wepoker辅助工... 透视有挂!wepoker辅助工具,xpoker怎么辅助(透视)总结教程(证实有挂)-哔哩哔哩1、用户...
透视真的!佛手在线大菠萝技巧,... 透视真的!佛手在线大菠萝技巧,wejoker透视方法(透视)推荐教程(发现有挂)-哔哩哔哩1、该软件...
今天上午!wepoker有透视... 今天上午!wepoker有透视吗,we-poker辅助软件教程(透视)详细教程(有挂教学)-哔哩哔哩...
最新消息!wepoker永久免... 最新消息!wepoker永久免费脚本,wepoker辅助器下载(透视)专业教程(有挂总结)-哔哩哔哩...
此事备受玩家关注!有哪些免费的... 此事备受玩家关注!有哪些免费的wpk辅助码,xpoker怎么辅助(透视)了解教程(有挂方略)-哔哩哔...
此事引发网友热议!wepoke... 此事引发网友热议!wepoker好友助力码,wepoker怎么买辅助(透视)揭幕教程(确实有挂)-哔...
透视总结!哈糖大菠萝软件下载,... 透视总结!哈糖大菠萝软件下载,htx矩阵wepoker辅助(透视)解迷教程(有挂猫腻)-哔哩哔哩该软...
据目击者称!wepoker私人... 据目击者称!wepoker私人局辅助,wejoker私人辅助软件(透视)关于教程(有挂方式)-哔哩哔...
网友热议!拱趴大菠萝辅助方法,... 网友热议!拱趴大菠萝辅助方法,wepoker有没有插件(透视)揭幕教程(揭秘有挂)-哔哩哔哩1、打开...