Closed Sonphil closed 4 years ago
Hi @Sonphil Thanks for reporting this issue, will surely look into this. Meanwhile, if you want to fix this, you can contribute to it as well.
@therealshabi I made a small change and opened a pull request: #39
Merged your PR into the dev
branch. Will merge and release from the master after testing the implementation. Thanks for your contribution
How to set Multiple images in viewpager??
view.setImage(url[i], new Function2<ImageView, Object, Unit>() { @Override public Unit invoke(ImageView imageView, Object image) { Picasso.get().load((String) image).into(imageView); return Unit.INSTANCE; } }); } catch (MalformedURLException e) { e.printStackTrace(); }
The above code not working
@Poornima-Dixit is it showing any error? What exactly is happening? Can you please share the stack trace?
view.setImage(url[i], new Function2<ImageView, Object, Unit>() { @override public Unit invoke(ImageView imageView, Object image) { Picasso.get().load((String) image).into(imageView); return Unit.INSTANCE; } }); } catch (MalformedURLException e) { e.printStackTrace(); } The above code contains ERROR when I am running It's giving error on Function2 & Unit
How to solve can you plzzz help????
@Sonphil
@therealshabi
@Poornima-Dixit Are you using Java 8 in your project, because this will work if your project is running on Java8?
How to check that??Where it is mention in android studio?
I am using Java 8 still giving error
Have you used Kotlin??
@Poornima-Dixit this library also has a Kotlin support, so you can use Kotlin syntax as well (for syntax please refer the Readme). Having said that I'm curious why it is not working for you in Java. Can you please share the codebase or a test code for me if you can in which this code is not working. I'll try to debug and present the solution to you as soon as I can
@therealshabi Yes sure The program is running when I am adding only one image MainActivity.java File:- protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
final FlipperLayout flipperLayout = findViewById(R.id.flipperLayoutTwo);
String[] url = {"https://blog.eap.ucop.edu/wp-content/uploads/2016/01/Julie-Huang-27.jpg",
"https://source.unsplash.com/random",
"https://i.pinimg.com/originals/18/40/72/184072abb72399c23ab635faaa0a94ad.jpg"
};
for (int i = 0; i < url.length; i++) {
FlipperView view = new FlipperView(getBaseContext());
view.setDescription("Cool" + (i + 1))
.setDescriptionBackgroundColor(Color.TRANSPARENT)
.resetDescriptionTextView();
flipperLayout.setCircleIndicatorHeight(60);
flipperLayout.setCircleIndicatorWidth(200);
flipperLayout.removeCircleIndicator();
flipperLayout.showCircleIndicator();
view.setOnFlipperClickListener(new FlipperView.OnFlipperClickListener() {
@Override
public void onFlipperClick(@NotNull FlipperView flipperView) {
Toast.makeText(getBaseContext(),
"Here " + (flipperLayout.getCurrentPagePosition() + 1), Toast.LENGTH_SHORT).show();
}
});
view.setImageDrawable(R.drawable.lean);// this is only one image
flipperLayout.addFlipperView(view);
}
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
.setDrawerLayout(drawer)
.build();
// NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
// NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
// NavigationUI.setupWithNavController(navigationView, navController); }
@therealshabi Now the Problem is that when I am adding below code its giving error:- try { view.setImage(url[i], new Function2<ImageView, Object, Unit>() { @Override public Unit invoke(ImageView imageView, Object image) { Picasso.get().load((String) image).into(imageView); return Unit.INSTANCE; } }); } catch (MalformedURLException e) { e.printStackTrace(); }
@therealshabi
@Poornima-Dixit I'll check this asap and will revert
@therealshabi Yes sure please do it on ASAP.IT's urgent
@Poornima-Dixit The images that you're trying to load, are they a drawable, url or what?
Yes,they are drawable
@therealshabi
For drawable set image like:
try {
view.setImage(drawableList[i], new Function2<ImageView, Object, Unit>() {
@Override
public Unit invoke(ImageView imageView, Object image) {
imageView.setImageDrawable((Drawable) image);
return Unit.INSTANCE;
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
@therealshabi Yes But it is giving error on"Function2" & "Unit" Where is these classes available?
Ohh! Are you having Kotlin dependency in your project, these are Java version of Kotlin callback method
No I haven't added here ,How to add it??
Can you please google it, it'll be a simple process.
@therealshabi Yes I solved it.Just One Query I had
@therealshabi May I Ask one query?
@therealshabi Thank you so much for your support answers.Just last one error is "setImage"giving error.How to solve it
Can you please specify clearly, what error it is giving?
@therealshabi above is the error
This is weird, can you please clean and build the app and check again?
Ok
When the user scrolls to the second item, if the layout has only two
FlipperView
s, theViewPager
scrolls back immediately to the first item. TheViewPager
should remain at that position (or switch after a certain amount of time if auto cycle is enabled).Here is an example:
This problem doesn't occur when there are more than two
FlipperView
s.Version of the library used: 1.6.0