Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在androidx.appcompat.widget.SearchView上设置建议_Java_Android - Fatal编程技术网

Java 在androidx.appcompat.widget.SearchView上设置建议

Java 在androidx.appcompat.widget.SearchView上设置建议,java,android,Java,Android,我正在制作一个android应用程序,其中我使用了androidx.appcompat.widget.SearchView我有一个arraylist,其中包含不同的值,现在我想从该数组列表中设置androidx.appcompat.widget.SearchView的建议。我试了很多,但效果不好。 我还在onQueryTextChange中测试它是否工作,但它不工作,因为当我更改文本时,我没有得到toasr public static ArrayList<String> phoneN

我正在制作一个android应用程序,其中我使用了
androidx.appcompat.widget.SearchView
我有一个arraylist,其中包含不同的值,现在我想从该数组列表中设置
androidx.appcompat.widget.SearchView
的建议。我试了很多,但效果不好。 我还在
onQueryTextChange
中测试它是否工作,但它不工作,因为当我更改文本时,我没有得到toasr

public static ArrayList<String> phoneNo=new ArrayList<>(); // This one contains names
public static ArrayList<String> cname=new ArrayList<>(); // This one contains phone numbers
private SimpleCursorAdapter mAdapter;

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
 // Inflate the layout for this fragment
        View root= inflater.inflate(R.layout.fragment_messages, container, false);
        final String[] from = new String[] {"contacts"};
        final int[] to = new int[] {android.R.id.text1};
        mAdapter = new SimpleCursorAdapter(home_Activity,
                android.R.layout.simple_list_item_1,
                null,
                from,
                to,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

}
 @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
searchView = (SearchView) view.findViewById(R.id.sView);
     searchView.setSuggestionsAdapter(mAdapter);
        searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
            @Override
            public boolean onSuggestionClick(int position) {

                Cursor cursor = (Cursor) mAdapter.getItem(position);
                String txt = cursor.getString(cursor.getColumnIndex("contacts"));
                searchView.setQuery(txt, true);
                return true;
            }

            @Override
            public boolean onSuggestionSelect(int position) {
                // Your code here
                return true;
            }
        });



        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                populateAdapter(s);
                Toast.makeText(home_Activity, "ok", Toast.LENGTH_SHORT).show();
                return true;
            }
        });


}
publicstaticarraylistphoneno=newarraylist();//这个包含名字
公共静态ArrayList cname=新ArrayList();//这个包含电话号码
私人简易程序或适应程序;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
视图根=充气机。充气(R.layout.fragment\u消息,容器,false);
最终字符串[]from=新字符串[]{“联系人”};
final int[]to=new int[]{android.R.id.text1};
mAdapter=新的SimpleCorsorAdapter(家庭活动,
android.R.layout.simple\u list\u item\u 1,
无效的
从…起
到
游标适配器。标志(寄存器、内容、观察者);
}
@凌驾
已创建公用void onview(@NonNull视图,@Nullable Bundle savedInstanceState){
super.onViewCreated(视图,savedInstanceState);
searchView=(searchView)view.findViewById(R.id.sView);
searchView.setSuggestionAdapter(mAdapter);
searchView.setOnSuggestionListener(新的searchView.OnSuggestionListener(){
@凌驾
公共布尔onSuggestionClick(整数位置){
Cursor Cursor=(Cursor)mAdapter.getItem(position);
String txt=cursor.getString(cursor.getColumnIndex(“联系人”);
setQuery(txt,true);
返回true;
}
@凌驾
公共布尔值onSuggestionSelect(整数位置){
//你的代码在这里
返回true;
}
});
searchView.setOnQueryTextListener(新的searchView.OnQueryTextListener(){
@凌驾
公共布尔值onQueryTextSubmit(字符串s){
返回false;
}
@凌驾
公共布尔值onQueryTextChange(字符串s){
民众适应者;
Toast.makeText(home_活动,“ok”,Toast.LENGTH_SHORT.show();
返回true;
}
});
}

这方面运气好吗?这方面运气好吗?