Re-Arrange the Fragments in View Pager dynamically - android

Re-Arrange the Fragments in View Pager dynamically .
I am adding and removing fragment from View-Pager and also have to follow the sequence of fragment while adding & removing
Lets Say I am adding & removing on basis of a list . there is a list with 6 items. Items-List : Card-1 Card-2, Card-3, Card-4, Card-5, Card-6.
Now, I want to manage for Example: if I click randomly like Clinked (Card-6) , Clinked (Card-2) ,Clinked (Card-4) ,Clinked (Card-3) ,Clinked (Card-1) ,Clinked (Card-2), Here Order has been changed & I want it to be added sequentially
I've tried like : list.add(Clicked -Card) but this doesn't manage order as use can clicked randomly any position & also cannot used list.add(position,item) as if user click on last or other position that is more than Pager size will throw IndexOutOfBound Error

Related

collapse recyclerview with different view types

So, I have a recyclerview with multiple view types. I'm using this link to generate my adapter class, becauseI have multiple viewholders in my recyclerview. Now the problem I have is with collapsing certain items inside it. What I want is whenever I press
the green toggle, item 2 and 3 in the list should collpase but 4,5,6 should remain upon,unless you have clicked on the green item ofcourse. I tried many ways to approach this but I can not achieve this with the link provided. Is there any way I can achieve this?
When you click collapsing button you have to remove your collapsing data from your all source list. When you remove your item from your list recyclerView automatically animates it.After that when you want to show it again you have to insert it your list again and notify that.RecyclerView also animates again when you insert it. There is a useful link here for inserting and removing special data from recyclerView https://medium.com/#suragch/updating-data-in-an-android-recyclerview-842e56adbfd8

How to create this view(at most 4 images in a page then swipe rest as same)?

Let's say I have dynamic number of items coming from server. I can only show 4 items at most in one page. Other pages whould be accesible with swipe Please have a look at the image below. What is the best way to achieve this?
This could be achieved using
View pager
Pager Indicator
A fragment with four view (Use proportionate layout) or use grid
view
Approach
The decision on number of pages will lie on the data received from
server.
For example:
if number of item recieved is 17
the number of pages will be 17/4+ 1(only if 17%4>0)
pass the page index to the fragment along with the complete list.
For example if page index in view pager 4
Make sure to keep the check ( index+4<=size of list of item)
if (index+4>size of list of item) then the the item to be displayed will start from index and will go on till the size of list.
if(index+4<=size of list)the item to be displayed will start from index i.e 4 in this case till next four element in list of items provided to the fragment.
In this way you can always get the required item out of the complete list

Android: How to dynamically replace a list view with another list view like Instagram with onClick?

I'm building an android app and I'm trying to replace a list view with another list view if you click a button, like the notifications page on Instagram. On that page, if you click on the top "following" button it will show you a listview of what your followers have liked. If you click on the "you" button it will show you a listview of what people have liked your photos.
Any help would be greatly appreciated!
You can do it by following ways,
1. add Two listviews and can change the visibility as per your requirement.
2. On button click you can load the other data into same list view and can update your adapter in the same list view.
in 1 you have to load two list view at first which will consume more time if data is larger sure you can write a login in asynctask to load list views in background thread.
in 2 you have to update your adapter at the button so you will have to provide some progress bar of dialog for user while you list view is getting update.
You can use either of this whichever suites you best.
Simply , You don't need to switch Listview , you only need to switch adapters .
eg, you can switch to mFollowingAdapter when clicked on Following button and switch to mYouAdapter when you select "You" tab. that's it.
You should write a list, that has a custom adapter. This adapter will be able to display BOTH views you want to display.
If the data to be displayed is the same format (ie. both have an imageview next to a textview), you are in good shape.
When you want to switch to a different list, get the information you would like to display, replace the data in your the collection backing your list, then notify the list that the data has changed, and it should redraw.
So, this might look like:
create ArrayList() with data A
setup List, with this data and display
replace the ArrayList() with data B
call listView.notifyDataSetChanged
You can still do this if the Data A, and Data B have different views, in this case, you would need to handle this logic in your custom adapter.

Particular Expandable View visible at one time

I am making an app in which the 1st layout contains clickable List having 12 items
and on clicking of each item, the user goes to a new Activity that has Expandable list View.
And I have concerned the tutorial at https://www.youtube.com/watch?v=BkazaAeeW1Q
and do I need to make 12 Activities each containing an Expandable View or is it possible that one Activity containing 12 Expandable Views but only one Expandable view is visible at a time (and which among them is visible will be dependent on Item clicked on the List View of 1st layout)
Hope I am able to make my point clear?
Use List Fragment, by using fragment no need to create 12 activity ,you just replace the container with view.
Also we can make one expandable view at one time, check on child click and onGroupexpand method for that.

Showing recursive lists inside a tab view

Algorithm question here.
I'm creating an app that shows a legal document, with tabs for navigation (TOC, bookmarks, etc).
Inside the TOC tab, I need to show a multilevel table of contents. At the 'leaf' of the toc, I need to show a TextView
So, I could have:
tab1: List -> List -> List -> List -> List -> TextView
or
tab1: List -> List -> List -> TextView
or
tab1: List -> TextView
depending on the chapter, section, subsection, subsubsection structure of the book I'm showing.
Now, it doesn't matter how deep you are, the TabHost needs to be ALWAYS PRESENT, to provide the main navigation. (Yes, I asked, and I need to use the tabs, not a menu.)
The question:
How do you implement the recursive List inside the FrameLayout of a tab? Or should I use a ListView styled as tabs and just not use the TabHost?
Ideas?
Thanks!
llappall
Okay. Number one you cannot put ListViews inside ListViews, ScrollViews, GridViews or anything scrollable for that matter (i.e. a ListView item cannot be ListView). It might compile, it might run, but the results will not be what you expect or want. This is because a ListView cannot have a height which is set to WRAP_CONTENT.
You can have a two-level list (ExpandableListView) but if you require more levels than that you will have to implement the functionality yourself by extending ListView or ExpandableListView.
You can also have sectioned lists, and lists with multiple item types, but there is no way using the default SDK components to get a 5-level list.
Number two: Yes you can have a ListView inside a TabHost. You won't be able to use a ListActivity, but that just means you'll have to call the ListView methods directly:
ListView myList = findViewById(R.id.myList);
myList.setAdapter(myListAdapter);
instead of calling the inbuilt ListActivity methods.
Just place your ListView inside the FrameLayout in your layout file. If you have three tabs and the ListView is the first element inside the FrameLayout, then it will be displayed as the content for the first tab. If it is the second element, it will be the content for second tab and so on.
The only way you could implement a recursive list with inbuilt components would be to use a single ListView, and then change the contents of the adapter of the ListView when a user selects an item (essentially a drill-down menu using a single ListView). You'd also need to catch the back button with onBackPressed in order to allow the user to navigate back up the list, or provide a back button somewhere.

Categories

Resources