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.
Related
I need to create recyclerView with collapsing items. For example, I have a list of 10 items. By default, I only need to flip the first 2 elements. But by clicking on the "See all" button, I need to display all the items in the list. And vice versa, by clicking on the "Hide" button, you need to leave only the first two items in the list. Here is an example:
I suppose to implement it like this: create a flag that determines whether the full list is displayed or not, and by clicking on the button, depending on the flag, send the full list to the adapter or cut it to two elements and call notifyDataSetChanged().
But this solution seemed to me not very good, perhaps there is a more elegant solution.
Note: I don't need nested collapsing elements. I just need to display two items from a list or all items.
Please help me.
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.
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.
Is there a way to automatically create a ListFragment containing just TextViews and when an item in the list is clicked, create another ListFragment with TextViews and so on, up until an item with no children at which point clicking on it launches some other action?
Basically I just need to drill down through categories and subcategories and sub-subcategories and so on until I reach a value that doesn't have it's own list and instead corresponds to another action entirely.
I feel like there might be an easy way to do this through XML, but I'm not 100% sure.
I have an activity on the top of it there are some buttons from which when a button pressed it loads the dialog with country list and when user choose choose the country it will load the channel list below buttons.
so when activity start it shows blank screen until user choose the country
so i want to show a list when activity will start and then same procedure will follow as above.
but how can i load two different listview?
i tried
acivity start
load the default country channel's list
buttonclick listener
perform click {
load the another list
}
using the base adapter class found here.
Just switch adapter to current list (this is the easy way to do it)
OR
In your android xml file, where you create your activity, create two listviews with different ids. First listView will have android:visibility="visible" (this one will be shown first) and the second one will have android:visibility="gone"(you will make this visible when you perform the click).
When you want to switch the lists, just set first listview visibility to View.VISIBLE and the other one to View.GONE, from code.
Don't forget to switch adapters for different lists (this may be a bug source)
I would do following
Have a flag like isCountrySelected
Change your adapter and onitemclick handler so that according to isCountrySelected, you either load channel list or country list.