BottomSheet Dialog Opening More Than One Time
I am using bottomsheetlayout pop up for social media sharing. now issue is , it is opening more than one time. please help me to solve this.
on my button click I call asynctask for download Images.
@Override
protected void onPostExecute(Void res) {
super.onPostExecute(res);
//prodImageUri1.addAll(prodImageUri);
if(single_rdb.isChecked())
{
createImageBitmap();
}
else if(allimg_rdb.isChecked())
{
temps=new ArrayList<>();
for(int i=0;i<prodImageUri.size();i++)
{
if(i==8)
{
break;
}
temps.add(prodImageUri.get(i));
// System.out.println("SIZE "+temps.size()+"TEST1 "+temps.get(i));
createImageBitmap();
}
}
}
here I call createImageBitmap method. now inside this method I have bottomsheet.show
public void createImageBitmap(){
...................
...................
if(single_rdb.isChecked())
{
header_image.setImageURI(prodImageUri.get(0));
imageview1.setVisibility(View.GONE);
imageview2.setVisibility(View.GONE);
imageview3.setVisibility(View.GONE);
horizontal_image_layout.setVisibility(View.GONE);
}
else if(allimg_rdb.isChecked())
{
arrayListClone = (ArrayList<Uri>) temps.clone();
for(int i=0;i<arrayListClone.size();i++)
{
//System.out.println("FAFA"+arrayListClone);
header_image.setImageURI(arrayListClone.get(i));
// System.out.println("SIZE "+temps.size()+"TEST "+temps.get(i));
}
imageview1.setVisibility(View.GONE);
imageview2.setVisibility(View.GONE);
imageview3.setVisibility(View.GONE);
horizontal_image_layout.setVisibility(View.GONE);
}
for(int i=0;i<arrayListClone.size();i++)
{
if(i==1)
{
break;
}
System.out.println("This is check");
addPhotoBottomDialogFragment = new BottomSheetSharingFragment1();
addPhotoBottomDialogFragment.show(((FragmentActivity)context).getSupportFragmentManager(),
"add_photo_dialog_fragment");
}
What I am trying to achieve is, bottomDailog should open only one time, right now it is opening as per size of arraylist of Image. For Example if arraylist will have 3 images it shows dailog three time and placing on one another.
Answer
Okay remove the bottom sheet dialog call from your for loop and place it outside the for loop it's executing multiple times because of the for loop where until the for loop reaches the end of your array list it will keep executing. So simply remove bottom sheet and place it outside the for loop You're facing problem because of this piece of code:
for(int i=0;i<prodImageUri.size();i++)
{
if(i==8)
{
break;
}
temps.add(prodImageUri.get(i));
// System.out.println("SIZE "+temps.size()+"TEST1 "+temps.get(i));
createImageBitmap();
}
so simply remove bottom sheet dialog from your createImageBitmap(); method and place it outside the method.
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View