Dialog Fragment: Issues with a bigger custom layout

from the CommonsWare Community archives

At June 23, 2018, 4:48am, Shahood asked:

Hi,

While going through the chapter Dialogs and Dialog Fragments, I took the sample app Dialogs/DialogFragment a tad bit further by adding another 7 LinearLayout blocks containing a title TextView and an EditText. I was testing how I would be able to access the bottom views; would it let me scroll the views or would I have to hide the keyboard if I need to go to, let’s say, the last EditText field. Also, I wanted to see how I can access the positive and negative buttons. Would they be visible as a footer if the views can’t fit the screen; and what would happen when the keyboard is on screen.

I tried wrapping up the whole view in a ScrollView, added the following in menifest.

android:windowSoftInputMode=“adjustResize”

Overridden onViewCreated() (couldn’t think of a better place to put this line in) of the fragment and added the following in it before calling the super method:

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Following is the result:
As long as the keyboard is not visible, the things go fine: dialog title stays as a header, buttons as footer and the custom layout shows in the middle and we can scroll it to access all the views.
When the soft keyboard is on screen, button are never accessible, dialog title is visible as long as the there is enough space on screen for it to be shown. When we try to access the bottom views, it scrolls away, although it ain’t part of the ScrollView.

So, is there a way to design the custom view such that the title stays on screen as a header, the buttons as a footer, and the custom layout in the middle is scrollable whether or not the soft keyboard is visible?

Thanks

gist link


At June 23, 2018, 12:29pm, mmurphy replied:

I have no idea, sorry. I would not create a dialog that large and complicated, and so I have not had to deal with your particular problem.

Note that AFAIK android:windowSoftInputMode=“adjustResize” only affects the activity’s window,and I have not tried setSoftInputMode() to know if there are any particular rules about the timing of when you need to call that.


At June 23, 2018, 12:46pm, Shahood replied:

I have no idea, sorry. I would not create a dialog that large and complicated, and so I have not had to deal with your particular problem.

I actually need to have this functionality in another app where I want to use an AlertDialog in order to save an item. The said dialog contains various input fields that are either EditText or AutoCompleteTextView…and finally, those two buttons. I can have such a form in a separate fragment, yes but I like having it on a dialog better.

Anyhow, would u allow me to use this code and raise a similar question on SO?


At June 23, 2018, 12:59pm, mmurphy replied:

would u allow me to use this code

Little if any of that is my code. You are welcome to use any of the books’ sample apps’ code under the terms of the Apache Software License 2.0. But if you make substantial changes, such that my “contribution” is not really identifiable, that is your code and you can do with it whatever you like.


At June 23, 2018, 2:27pm, Shahood replied:

I’m also gonna try this same layout in a Fragment instead of a DialogFragment and see how it behaves there. Will get back to u soon.