Reputation: 149
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...
Upvotes: 2
Views: 316
Reputation: 149
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));
}
}
Upvotes: 1
Reputation: 506
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.
Upvotes: 0