I am relatively new to android.
I have to design an Activity that has a 2 * 4 grid.
Each grid item will have an image view and a text view
On swiping left or right the user will move to a different page but the UI will remain the same.
Just the data set to the grid will change.
I want the number of pages to be configurable.
Also I want to reuse the same xml file for UI instead of creating two new xml files for the other 2 pages.
Which is the best possible way and the most efficient way to implement this and any examples on how to do this ? Any help will be appreciated. Thank you
I think you can use ViewPager with Fragment. You can see in this example https://developer.android.com/training/animation/screen-slide.html
You could achieve this with a ViewPager, each page (probably Fragments) containing a RecyclerView with an Adapter..
The fragment code, layout file and adapter implementation would be identical for every page. You just need to pass in the respective data to display to each page.
Related
I'm implementing a fragment which is based in a ViewPager for sliding slides (see here).
So, I would like to know if it's possible to get a new sliding tab dynamically, based on a text length (which is displayed in a TextView inside of ViewPager) I want to display inside that ViewPager (to get a similar book view).
Thank you.
Go back to that link you posted about ViewPager and re-read it focusing on PagerAdapter. The concept is similar to the list adapter. So for example, you create a PagerAdapter that will take your content (in a constructor, for example), and determine how the content is broken up into pages. Say you pass in some content and your PagerAdapter determines there are 17 pages. Your override for PagerAdapter.getCount() would return 17. Then in instantiateItem() (or maybe getItem(), if you're using FragmentPagerAdapter), you would create the view that is to be displayed at page position, which is a parameter.
Fair Warning! It sounds like you want to page some text horizontally like pages in a book. You should know that TextView won't be able to do things like, "well I'm this size, so I can display this much text". You will need to use things like android.text.StaticLayout to figure out stuff like that. Do-it-yourself text layout is advanced Android programming, so brace yourself.
I am new to android and I am working on a project that displays cards (like on Google Now but all cards are the same size). My question is, is it possible to add the same fragment (a general design for the card) multiple times to the same screen and have them be position after each other in a row or column? If so how would I go about that?
Yes you can. Create a template fragment (eg. TempFragment extends Fragment). Then initilise a new TempFragment each time you need with the data you want to display and use a FragmentManager to add it to the view you want. As for the row or column layout you can use TableLayout in your main layout. Your question is very vague and I'm afraid I can only help you this far.
You can use your Adapter's item to implement your fragment. Google's Api Demos has this kinds of example( Support4Demo).
You can use RecyclerView with its Adapter class. Google uses same subject for displaying a similar layout items.
https://www.androidhive.info/2016/01/android-working-with-recycler-view/
you can see here ... there is all you need.
I want to create a grid view similar to the image shown below. The category panel
can be scrolled horizontally and has a list of items. When clicked on a category the grid view is loaded dynamically and selected category is underlined/highlighted. Grid also loads images on scroll vertically as well.
Currently, I download a xml with images to a gridview and use Picasso library to load images.
What I want to know is
1) how to add the categorizing to my current implementation?
2) Do I load a single xml with categories and image list first and then load images after or do I keep a xml per category.
3) How do I manage the grid adapter when user clicks on different categories
4) How do I design the category scroll view at top?
Well, after reading the question thoroughly your not asking for a Solution, your asking a Suggestions !!
So, i come up with some approaches to guide you regarding the implementation.
As you mentioned in your question, you have different different categories and each of the category having the grid of images. one main hing is like you can select the category / you can swipe the grid view to change another category in your app.
Why not, these all you can do. Did you used Fragments & ViewPager ?
by combination of Using ViewPager with FragmentPagerAdapter you can achieve the same what your planning.
Here i am explaining you in details >>
your category size is fixed ?
if yes you can make static fragments for those. if it is not fixed in a size / order then you can create PageAdapter with the list of your categories and set that adapter to your view pager in home screen
Now you have a categories, After that you can create a corresponding fragment activity to hold a gridview and based on the page adapter position you can load the categories into the gridview
Here your all fragments having the same gridview, so you easily control it by using vie pager and respective gridview loading and controls you can made in the fragment.
By using this, there is no way of creating such no of xml files & classes as you mentioned in the question. It is a simple and easy way to handle
The big advantage in this approch is like, you no need to bother about the size of categories (as your making as adapter, 35,50,100 that number go's on) it will add the categories to your view pager
fragment loading also you can make a single fragment and re-use the same in all over application as every category having the same grid view .
Here is a sample example to use the fragments with gridviews in a view pager and this
Also you can find a lot of examples in SOF like this..
if you find any difficulty then come with a piece of code/trail what you did and ask in SOF.
Let me if any clarifications required.
I am working on an android app and I have to Implement the below screen. That screen has two buttons at the top just like we have in tab view, on changing the button 1 is for opening the Picture view and other is to view the videos screen. Below that buttons I have to Implement two listviews for video screen that will each contain one header like one for songs (below that will be a listview of songs) and second header is for films (below that will be a listview of films). And the data for both songs and films is coming from two different services, just like for songs http://mywebsite.com/songs and for films http://mywebsite.com/films. Now I am little bit confused about the UI that there are many alternatives to implement it, but not sure which one will be best for me.
Please give me some ideas about how to implement it. Should I use a Radio group for the above buttons and on State change it should call the respective method, for a view of video and picture. But for each view I will have to make two listviews , just like in the video screen one for songs and other for films. And making two listviews is little bit complex than a single listview. Is there any way to handle it by only one adapter and in that view the same headers should be there. Ad if someone has any good idea then please share it. Any help will be highly appreciated.
You should consider to use fragments for your tab functionslity.
An alternative for two list views could be one expendablelistview. With two groups. You can add multiple types of items to any list view. You just have to overwrite the getitemtype Methode and define the different types you want to display in your listview.
1) hey bro, firstly u hv to create a swap view with a navigation tab functionality on it. check out this link http://developer.android.com/training/implementing-navigation/lateral.html
2) the above example will provide you 2 fragment pages that you can use for picture and videos separately. You can create the layout of every page as you like via using separate fragment with their own layout as you wish.
3) Now in video layout fragment, you can use 2 list views one by one in the linear layout with orientation vertical. Check this link to get idea how to implement your custom list view. http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
4) You have to put the value of Android:weightSum="2" in parent layout( linear layout with orientation vertical) and put Android:layout_height="0dp" & Android:layout_weight="1" in each list view. This will provide equal space for both the list view in single screen for each type of device.
I need to implement an application which uses a sliding view (ViewFlipper) for one of its activity, this activity displays information stored on and array and passed from the previous activity via intent. The number of slides or tabs is expected to vary depending on the number of elements in the array. i.e for 4 elements in the array,we shall get 4 slides and when there is only 3, we have the same amount of slides displaying respective information accordingly.
Any idea on how to implement this, an example if possible? I am very new to android development. please help
Create an .xml file now implement a view flipper design the layout of how each pages work. I suggest using a relative layout and add those views inside the view flipper. Seems pretty basic now go search tuts on .xml, viewflippers, types of layout, textviews, and don't put questions here next time asking for answers. We are a community after all helping people with problems who actually tries to do something not for copy and paste people.
For this purpose it's best not to use the ViewFlipper, but instead use a ViewPager to which you can dynamically add 'subviews' (pages) using a PagerAdapter. ViewPager will provide performance benefits over ViewFlipper as it loads (and removes) pages on-demand (like a ListView).
Set-up of the ViewPager is in essence the same as setting up a ListView. You can use the ViewPager on Android <3.0 devices using the compatibility library.
Create your own class that extends PagerAdapter, and set mViewPager.setAdapter(mAdapter);. In your adapter, in the method instantiateItem() you will build your 'page' and add it to the parent with mViewPager.addView(newView);.
For a more detailed example of how to set-up a ViewPager see my answer here.