Implementing fixed height scrollable listview in DialogPreference - android

I have sub-classed a DialogPreference and implemented a folder picker using ListView. Everything is working nicely when moving up and down the folder tree and displaying the folders in the listview.
My problem is that the dialog window grows and shrinks when I move up and down the folder tree (due to the different number of sub-folders in each folder). I am keen to keep the dialog window a fixed height as the folder tree is navigated.
As a solution I specified a fixed height for the list view and this works well in portrait mode, however I have noticed that when I switched to landscape mode the listview would not scroll and the only reason I can come up with is that the number of items in the listview is less than the fixed height so the scrolling is not enabled. This is a bit of a pain since it truncates the list in landscape mode and the user can not scroll down to see the rest of the list items.
Does anyone have any suggestions? I am not too hung up about using a dialog (full-screen presentation is OK as well), so any alternatives that can work within the PreferencesActivity is OK too.
Thanks in advance,
dsana123.

You can set the height of listview dynamically.
See
How can I put a ListView into a ScrollView without it collapsing?
So, you can solve the problem like this.
set the height of dialog
add listview in scrollview
set the height of listview dynamically.
If you followed above, you can scroll scrollview containing listview in landscape mode.

My best suggestion, create a custom landscape layout with a different fixed height than portrait. If you get a fixed height working, make sure you use display independent pixels and not fixed pixels.
You should be able to make full screen work as a separate Activity without a problem. ListPreference should work in a PreferenceActivity. My answer is vague because no code showing the problem was provided.

Related

RecyclerView height changes if keyboard is visible

I have a RecyclerView in my app. It is part of a fragment (one of several) in an activity. The problem is, when the keyboard is closed it will max out in height and use its internal scroller. When the keyboard opens, the internal scroller turns off and the RecyclerView shows all its children.
The RecyclerView has the option for elements to be added or removed by the end user. In my full implementation, it shows four elements before starting to scroll (with the keyboard closed). When it is the sole fragment, it will max out its height at the screen height.
I've tried setting setting the NestedScrollEnabled to false and while this does stop scrolling, the items it would normally scroll to are no longer accessible. The RecyclerView still changes height depending on keyboard status so the 'hidden' rows become visible when the keyboard is open.
So in short, my RecyclerView is changing its height depending on keyboard visibility. How do I always make it show all its children?
Simplified fragment code that still shows the issue.
Java: https://gist.github.com/anonymous/bd46e137a0fb52f79399c11ba5be61bf
XML: https://gist.github.com/anonymous/c9bfb3f7577f75befc7aa6d5569311ce
I'm using com.android.support:recyclerview-v7:24.2.1
I've encounter an issue using last RecyclerView version.. and even AOSP project don't use the last RecyclerView version.
So ,maybe this will solve your problem, use 23.x.x version and let me know if that resolved the problem :)

How do I make UI elements fill the entire Android Screen

I am trying to add a bar similar to the "Today" bar here, but I cannot figure out how to force the width to match the screen. I am just using a simple textview (if there is a better way.. that's awesome, please tell it to me, but i cant find anything for it)
Here is what is happening with match_parent or fill_parent I recolored the textview to show the margins (that I dont want)
match_parent should fill the entire screen.
Check your parent activity layout or your fragment layout and you should find your margins there.
BTW, if you have a list of items like the one in the picture and you want it to have sections (like 'today', 'yesterday', etc) you should probably use recyclerview with headers instead of text view. Check this library for this, it's pretty easy:
https://github.com/cymcsg/UltimateRecyclerView

ContextMenu for blank space of an Android ListView

Is there a way I can get a context menu pop up when a user long presses on the blank space of a listview? I know that this can be done by setting wrap_content to the layout_height parameter of the listview. In fact I have been doing that successfully for a while. However, sometimes this wrap_content behaves very strangely and though there is enough space on the screen the listview restricts itself to a % of the screen and items scroll within that space. To avoid that problem I have moved to the path of setting the height as 0dp and weight as 1. However, that has disturbed the functionality I had in terms of long pressing the empty area of a list to add a new item to the list. Any help will be greatly appreciated.
Note: I have looked at multiple similar questions on SO throughout the day today but couldn't find any conclusive and elegant solution.
You can use ListView#addHeaderView() or ListView#addFooterView() to add extra view at the top or bottom of ListView, which you can make it looks like blank space.
Also I suggest you use match_parent to the layout_height attribute of ListView.

ListView inside ScrollView

So I am aware that I can't use ListView inside ScrollView, because ScrollView gets the focus in that case and ListView becomes non-scrollable. But I have a program that goes out of screen when in landscape mode and I need to be able to scroll down to see the rest of the program so I use LinearLayout(vertical) with ScrollView that contains the most of the program and under that ScrollView I got my ListView. Now I want to be able to scroll down to my ListView when I am in landscape mode but it won't let me do that, it stops me where ListView begins. Is there a some kind of solution for this, or is it better for me to make my program stay in portrait mode?
You are still trying to nest a ListView inside a ScrollView in landscape mode...
I suggest creating a new landscape specific layout with two columns: the left hand side contains UI elements inside the ScrollView and the right hand side contains the ListView. This way both Views will still support scrolling.
Simply save this new layout in a new folder res/layout-land with the same file name as the portrait layout in res/layout. The OS will automatically switch layouts when the orientation changes.
You can read more about this: Supporting Different Screens
This end result will be similar to the old Google Market image:
The left, green side can scroll if necessary and the right, white side will scroll as well.
Do away with the VerticalLayout and insert the rest of the content as header and footer views of the ListView

How to resize a single View in my Layout when the Keyboard appears?

I have built a search function for my app and i display the results in a listview that sits ontop of the rest of the layout.
the layout is optimized for honeycomb tablets.
everything works fine except that i do not want the keyboard to overlap my listview. i want to resize it in hight so it fits in the remaining space.
does anybody have an idea?
i know one can set the android:windowSoftInputMode parameter in the manifest but that is not working for me because it affects the whole activity. i only want to resize one single view.
If I understand you correctly, yes you want to use the android:windowSoftInputMode="adjustResize". Just set everything to android:layout_height="wrap_content" except for the ListView, which you set to android:layout_height="match_parent"; that should keep everything the same other than the ListView, which will be resized to fit the remaining space.

Categories

Resources