SV(VARIABLE)是列表视图中提供过滤功能的搜索视图....应用程序退出加载...删除搜索视图代码后应用程序运行良好...请帮助..我我被困......
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.contactfragment,container,false);
this.lstNames = (ListView) v.findViewById(R.id.lists);
sv=(SearchView)v.findViewById(R.id.searchContactLIST);
// Read and show the contacts
showContacts();
return v;
}
private void showContacts() {
// Check the SDK version and whether the permission is already granted or not.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, PERMISSIONS_REQUEST_READ_CONTACTS);
//After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method
} else {
// Android version is lesser than 6.0 or the permission is already granted.
List<String> contacts = getContactNames();
// String[] arr_contact=contacts.to
List<String> contacts_no = getContactNo();
String[] strarray = new String[contacts.size()];
contacts.toArray(strarray);
String[] strarray2 = new String[contacts_no.size()];
contacts_no.toArray(strarray2);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, contacts);
// lstNames.setAdapter(adapter);
adapter = new GetContactAdapter(getContext(), strarray, strarray2);
lstNames.setAdapter(adapter);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}
});
}
}