Extension development help casting

Hey, everyone I was developing an extension in which I am getting viewpager from blocks and I am casting it into ViewPager but gives a runtime error.

Code I have used

View viewp = viewPager.getView();
ViewPager pager = (ViewPager) viewp;

Error says it all.
You can’t convert view (linear layout) to view pager.
View Pager can be added only in a linear layout.
So convert given view to linear layout and add View Pager to it.

But I want to use ViewPager itself in my code(library needs it) .

Then you will have to wait for other’s replies.
I don’t know any method to use view pager directly. :slightly_smiling_face:

1 Like

I will be waiting. Thanks for replying and helping.

I am facing one more problem that I am getting viewpager from the blocks but I am receiving it as a LinearLayout. Which causes an error with casting.

Maybe Kodular ViewPager Component have used linearlayout and it have viewpager as a child view or maybe they are using linearlayout and replacing it with viewpager

Is there any way to fix that because I need a viewpager to be used in my code. I am thinking something like inflate.