2

The Touch Event works fine when there is image in the ViewPager. However, the Touch event doesn't work when there is no image / empty folder.

My app loads the images to the ViewPager depending on the user selected folder.

Code:

xml:

 <test.com.ExtendedViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="514dp" android:background="@drawable/no_image" android:visibility="gone" /> 

As you can see, the ViewPager displays the default image when the folder/directory is empty. However, the Touch event doesn't work.

public void LoadViewPager() { ImagePathList = new ArrayList<String>(); for (File file : listFile){ ImagePathList.add(file.getAbsolutePath()); } mViewPager.setAdapter(new ViewPagerAdapter(MainActivity.this, ImagePathList)); //Custom ViewPager Adapter mViewPager.setCurrentItem(LastItemPos); 

Adapter:

 @Override public View instantiateItem(final View view, int position) { final Zoom_ScaleImageView imageView = new Zoom_ScaleImageView(activity); imageLoader.loadImage(AdapterImageList.get(position), new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String path, View NoView, Bitmap bitmap) { imageView.setImageBitmap(bitmap); ((ViewPager) view).addView(imageView, 0); } }); return imageView; } 

How can I make the Touch event works in ViewPager when there is no image?

Thank you

Edit: See my solution below...

3
  • How do you set the on touch listener? Commented Mar 31, 2015 at 19:56
  • Try to put your image in a LinearLayout, and implement the onTouchListener on the layout. Commented Mar 31, 2015 at 20:01
  • Touch event is in this class Zoom_ScaleImageView. It is extremely long that's why I didn't include it. I got it from one of the open source and modified it. The reason I am using this open source class is because it has double tap to zoom. Thanks Commented Mar 31, 2015 at 20:05

2 Answers 2

1

I figured out a solution. It may help someone else. It may not be the best solution, but it is working for me.

Basically, I check to see if the arraylist is > 0 or not. If it is not > 0, then load the no image drawable.

public void LoadViewPager() { if(ImagePathList.size() > 0) mViewPager.setAdapter(new ViewPagerAdapter(MainActivity.this, ImagePathList)); else { //load the drawable ImagePathList.add("drawable") mViewPager.setAdapter(new ViewPagerAdapter(MainActivity.this, ImagePathList)); } } 
Sign up to request clarification or add additional context in comments.

Comments

0

It might work if you change android:visibility="gone" to android:visibility="invisible" in the xml file. because if it is gone, it can not be touched.

1 Comment

Thanks for the answer, but this is not the case because I set it Visible in a condition programmatically. The background image "no.image" does show up. I changed it as your suggestion, but it is still the same result. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.