I have ListView which has many items(rows), onClick of any item goes to the DetailActivity which explains more about that particular item. If I want to see the detail of the next item, I have to come back to the ListView and click next item. How to design to see the next or previous item's detail from DetailActivity by swiping it left or right.
I assume that you have a Custom Object and ArrayList of this object.
You need to have an adapter to Show this Arraylist into Listview
When you clicked the list item you need to pass your object from ListActivity to your DetailActivity
I think you are doing this fine until this part.
Then now, you can use ViewPager and its adapter in your DetailActivity.
When you click the list item, you need to pass your Arraylist and your object index to the DetailActivity.
In the DetailActivity, get your Arraylist, set your List into ViewPager adapter, find your object via index(that you clicked) and set ViewPager page index as your wanted item index.
If you manage this correctly, you can slide details of your content. You can ask ma anything to make this clear.
There is a tutorial of Using the ViewPager: http://architects.dzone.com/articles/android-tutorial-using
You could go with a ExpandableListView. No need to open a new screen or doing something which becomes hard to manage like Fragments. The user can show/hide detail just by clicking on the item.
A view that shows items in a vertically scrolling two-level list. This
differs from the ListView by allowing two levels: groups which can
individually be expanded to show its children. The items come from the
ExpandableListAdapter associated with this view.
Related
I have two Fragments. In Fragment A I choose item with its unique ID. In Fragment B I have recycler adapter that consists of those items. I would like to take item from Fragment A, and open Fragment B with recycler adapter set to the position of chosen item. I found that in order to open recycler adapter on specific spot, I have to use something like that rv.getLayoutManager().scrollToPosition(positionInTheAdapter). The question is: can I get that position by item's id? Or maybe there's a better way of what I'm trying to achieve.
Thank you
You must be passing a list of items in Fragment B. Now when you select any item in first Fragment A then all you need to do is run a loop through all list of items passed to adapter and match on which position the item id matches that position can then be passed to rv.getLayoutManager().scrollToPosition(positionInTheAdapter)
For more info on how to pass data among fragments you can check this article.
I have a listview with 5 items. Each item has a listview with 5 items. I would like to have this in a single activity using adapter. Is it possible?
Expandable lists let you create lists within lists.
They’re ideal for list items that have sub-categories. The user selects an item from a scrollable list and another list pops open. They can then make another selection from this list. Here is the example and tutorial about this:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
You can use the Expandable lists.
it will help whatever you want like in your main listview have 5 item and each item have number of more item it will child of that item.
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.
I'm using ListFragment in a ViewPager. Is there a way to populate an ArrayList with the visible ListFragment's list items everytime the user pages to a new page?
You can implement an (OnPageChangeListener) onPageSelected() for the ViewPager and use it to detect which page the user has switched too. Then you can use the ListView getLastVisiblePosition and getFirstVisiblePosition to find out which items are currently displayed in the listView. Then it's simply a matter of storing those items in an arraylist.
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.