public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
v = inflater.inflate(R.layout.fragment_fragment_home, container, false);
FloatingActionButton floatingActionButton=(FloatingActionButton) v.findViewById(R.id.picker);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ContextCompat.checkSelfPermission(getActivity() , Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
new MultiContactPicker.Builder(getActivity()) //Activity/fragment context
.hideScrollbar(false) //Optional - default: false
.showTrack(true) //Optional - default: true
.searchIconColor(Color.WHITE) //Optional - default: White
.setChoiceMode(MultiContactPicker.CHOICE_MODE_MULTIPLE) //Optional - default: CHOICE_MODE_MULTIPLE
.handleColor(ContextCompat.getColor(getActivity() , R.color.colorPrimary)) //Optional - default: Azure Blue
.bubbleColor(ContextCompat.getColor(getActivity() , R.color.colorPrimary)) //Optional - default: Azure Blue
.bubbleTextColor(Color.WHITE) //Optional - default: White
.showPickerForResult(CONTACT_PICKER_REQUEST);
}else{
Toast.makeText(getActivity(), "Remember to go into settings and enable the contacts permission.", Toast.LENGTH_LONG).show();
}
}
});
recyclerView=(RecyclerView) v.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
listItems = new ArrayList<>();
return v;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CONTACT_PICKER_REQUEST){
if(resultCode == RESULT_OK) {
List<ContactResult> results = MultiContactPicker.obtainResult(data);
for (int i=0;i<results.size();i++){
ListItem listItem = new ListItem(
"Name: "+results.get(i).getDisplayName(),
"Contact No: "+results.get(i).getPhoneNumbers()
);
listItems.add(listItem);
}
adapter = new MyRecycleAdapter(listItems,this.getActivity());
recyclerView.setAdapter(adapter);
Toast.makeText(getActivity(), "MyTag"+results.get(0).getDisplayName(), Toast.LENGTH_SHORT).show();
Log.d("MyTag", results.get(0).getDisplayName());
} else if(resultCode == RESULT_CANCELED){
System.out.println("User closed the picker without selecting items.");
}
}
}
How can I use this onActivityResult
in fragment? Whenever I run this code at last "adapter is not connected" if this method is used as protected it works but in fragment does not support protected can anyone help me, please.