Automatically inflating parent and children ListFragments? - android

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.

Related

Android. RecyclerView with collapsing items

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.

Is it possible to have different child views for an ExpandableListView in android based on a value from the parent adapter?

In the app I'm working on, I currently use a button to open a new activity that has a simple filterable listview in it. When the user clicks on a row in the listview, the selected value is returned back to the previous Activity to then have something done with it. This means I have two activities to do one function.
I was looking for a way to combine the two elegantly, and think that an expandablelistview is the way to go, but I'm not sure about one thing: Can the getChildView be overridden (custom expandablelistview) to inflate a different view based on a value in the parent group adapter?
My adapter selects two values from an sqlite database, an integer called "Type" and a String called "Move". I only show the "Move", but bind the "Type" to an TextView that's hidden. If I implement a single expandablelistview, I would need to somehow pass the "Type" to the drop down, so that it could display a different child view (allowing user to enter either weight, time, or reps, based on a type value of "1", "2", or "3".
Is this possible with a custom ELV that overrides the getchildview method? I see that you can get the parent position, and the child position, but besides using a global variable when the parent is clicked, I can't see anything that is passed to the child to know the value, text, etc that was the parent?
I found a nice implementation as well here: https://github.com/tjerkw/Android-SlideExpandableListView
But it seems too complex to try and override that, so I'm just going to try a standard Expandable List View if it's possible.
Thankss!
Edit: Here's a bad mockup of what I'm talking about. First drop would have a view with just a box and a button, second view might have a box and a button, but third view has two boxes, one for weight, one for reps, and then a button.:
The way to do that is to create one View Layout for all possible types you want to show in one item of the ExpandableListView.
You just override the Adapters getChildView and select Type and Move in their. Then you set the parts of your View to View.setVisibility(View.GONE) to ensure, the right kind of View is shown.

Extended list view: Show text input inside once clicked

I am working on a UI where I have a list view. Each row has 2 information. One is Product name and the other is product ID stacked one over other. So each row has 2 lines of data.
What i want to do with this:
Once a user clicks on each row, it will further expand and show one input and one spinner. So it is basically for putting in Quantity and unit of measure.
Please let me know if this is achievable and if I can refer to some example.
What I need is more like
Taskos To Do List | Task List
https://play.google.com/store/apps/details?id=com.taskos&hl=en
All i need is that the category will not be expandable. Only the items will be expandable. All i need is an example of such app and then I can take it forward.
I think it could be done... you would need to put the extra widgets in your row layout, populate them and hide them upon list creation, then in your onListItemCLick you could unhide them.
Note I have no idea if this would work, but it seems reasonable that it might and it's what I would try and do to achieve the goal.
listView cannot be expanded. however you can use an expandablelistView
But the kind of functionality you want cannot be done this way(I guess.).
You can use
registerForContextMenu("your list View");
to register your list view
onCreateContextMenu
for the kind of action you want to be performed in your case its dialog with EditText and Spinner to have input from user

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.

android listview

I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.

Categories

Resources