Grid of Images inside ViewPager - java

I am trying to implement a custom grid of images in one of my ViewPager tabs. The way I've approached this so far is putting in a GridView in xml, and inflating that through my layout. However, my onClick Listener isn't working.
Looks like that may not be the best approach because I've asked a question on it and resolving the onClick issue doesn't seem to be practical at this point.
Is there a better way to put a custom grid of images (plus some text, etc, on the image item) inside a ViewPager and retain its clickability?
I'm trying to improve my approach.

Related

ViewPager indicator with pictures

I want to have ViewPager with photos with the thumbnails at the bottom, like this
I saw some libraries that implements page indicators with dots or something, but I have no idea how to do it with custom different pictures. Also it's need to have an ability to implement animation, as on screenshot selected tab indicator bigger then unselected
The only solution I found is to make another ViewPager for thumbnails, but it must be more elegant solution
I guess this library is the nearest solution for your need.

Android navigation through multiple layouts

i have this app that i want to have a specific way of navigation. And so i made a research but i got confused. And i am begginer in android development.
i want to ask what kind of layout or anything i can use to achieve that. I dont search for super specific answer, just what is the thing that is doing the job i want. So there it is:
the blue block("choose a brand" view) has to be on that position at all times and only changing the text if needed. I want when one image button is clicked the whole green block with the image grid change into another xml layout. I want to call multiple layouts in the green block when i interact with the buttons of those layouts. Atm the green block is an <include layout ="layout.xml"/>
I really apreciate any answer. Sorry if is basic but i really tried to find the thing i need but so far i see solutions that prevent me from using simple inflaters. Thanks in advance
You have to use fragments for this scenario.
You will have a LinearLayout where the first element will be your blue block.
The second element will be a FrameLayout that you will change into the Fragment you need (usually it will have the ID container).
Create a Fragment and set the layout your layout.xml file.
Create a second Fragment with the desired layout you would like to change the green block.
As you click on a imageButton you will have to change the current Fragment with the desired one. Here you will see how to send objects to fragments.
You can find here a way to switch between fragments. In the ft.replace method the first id is the FrameLayout you will use as a container(see above).
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.container, new NewFragmentToReplace(), "NewFragmentTag");
ft.commit();
Be careful when you import fragments. If you use the support package you will have to use getSupportFragmentManager();
Read more on the android developer about fragments
I think what you are looking for is Fragment class, which can be used as reusable code that can be linked to a UI/layout.
From android documentation:
To create a dynamic and multi-pane user interface on Android, you need to encapsulate UI components and activity behaviors into modules that you can swap into and out of your activities. You can create these modules with the Fragment class, which behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle.
Read more here

How do I create a dynamically-generated CardView List?

I am wondering how we can create CardView Lists (dynamically generated cardview items). I'm surprised I can't find any info on how to create CardView lists on the developer.android.com site. I can usually find whatever I'm looking for.
I have seen quite a lot of stuff online but from what I've seen, its still using generic views, not CardViews. How can we create a list with cardviews?
I am wondering how we can create CardView Lists (dynamically generated cardview items)
Use ListView or RecyclerView. Use CardView as the root layout for your row layouts, wrapping around whatever the "real" stuff is in the row. And you're done.
RecyclerView will be the more common choice, simply because it was released at the same time as CardView. Many of my RecyclerView samples use CardView, such as this one and this one.
I'm surprised I can't find any info on how to create CardView lists on the developer.android.com site
That's because there is nothing much different about creating a list containing CardView widgets than there is about creating a list containing any other sort of widget. CardView is just a subclass of FrameLayout with a nice drop shadow effect. It is not rocket science, nor is it brain surgery.

Scrollable PagerTabStrip

I've been searching for this topic for a while, and can't find enough resources or tuts about scrolling a PagerTabStrip. I'm using the FragmentStatePagerAdapter and populates the PagerTabStrip with getPageTitle(int position). I'd like to know how to make the titles scrollable. I'd like to scroll the titles without affecting the view by the time I stop or select into a specific title, then that's the time the view gets updated. I've been thinking to use HorizontialListView but not sure how to start. Hoping to learn from you. Thanks.
Found this on docu:
PagerTabStrip is an interactive indicator of the current, next, and
previous pages of a ViewPager. It is intended to be used as a child
view of a ViewPager widget in your XML layout. Add it as a child of a
ViewPager in your layout file and set its android:layout_gravity to
TOP or BOTTOM to pin it to the top or bottom of the ViewPager. The
title from each page is supplied by the method getPageTitle(int) in
the adapter supplied to the ViewPager.
I been searching on this on the web, but I didn't get any relevant resources. I just found out another library called actionsherlock that enables the scrolling of tabs without affecting the view which is exactly what I need, instead of using PagerTabStrip's listener .
I'm also searching for the same thing. Too bad you have to make your own implementation or use third-party library. I have read that this library offer the feature of scrolling tab independent of the content. But I have not tried it out yet.
http://viewpagerindicator.com/?utm_source=androidweekly&utm_medium=toolbox
Do you actually mean the ActionBarSherlock? Do you have an example?

ViewPager or Fragments?

I need to make an application that will basically be a 5 "page" quiz with true and false buttons. I don't think that a new layout/activity is needed for each "page". That would be overkill. Would a fragment or ViewPager be appropriate? Does it break any Android Guidelines? They both seem to make sense to me. Maybe fragments a little more because of a tablet/alternate layout. Any ideas would be appreciated.
I've been using the ViewPager in one of my projects, for side swiping between similar yet distinctly different views.
It is working very well.
It depends on your flow. View Pager will work well if your users can randomly go through the views. If you want things to be in a specific order then ViewPager probably won't work.
you can achieved by creating 5 pages dynamically and load that in single layout/activity
By using dynamically load pages helps In future you want to add 2 pages of question its easy to do
According to your flow u can use the this also In same activity you can change the question just on click of button.
And if you want user to revisit all question u can use view pager.

Categories

Resources