Issue
I have implemented an onclicklistener on a button to open Gallery when I click the button in the app nothing happens
Code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_statusfragment,container,false);
imageView = view.findViewById(R.id.imageView);
button = (Button)view.findViewById(R.id.button2);
textView = view.findViewById(R.id.textView);
view.findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(),"Upload screenshot",Toast.LENGTH_LONG).show();
if(ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
requestPermissions(
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
2000);
}else {
Toast.makeText(getActivity(), "Choose Screenshot", Toast.LENGTH_LONG).show();
imageView.setVisibility(View.VISIBLE);
button.setVisibility(View.VISIBLE);
textView.setVisibility(View.VISIBLE);
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(intent,1000);
}
}
}
});
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_statusfragment, container, false);
}
it also does not display the Toast message
Solution
Instead of return inflater.inflate(R.layout.fragment_statusfragment, container, false);
do return view;
Answered By - Mihail
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.