Change layout when soft keyboard is shown - android

I would like to change the layout when an EditText is clicked and the softkeyboard is shown, so all EditText views are still visible.
I know that you can use the following two, but this is not what i'm looking for.
android:windowSoftInputMode="stateUnchanged|adjustPan">
android:windowSoftInputMode="stateUnchanged|adjustResize">
I've got 8 EditText views spread over the whole screen. When one is clicked to change a value I would like to still see all the ET views but nicely arrange and not pushed in a weird view.
Is there an easy way to do this?

I think you are going to have to do this yourself, but one technique might be ...
Create a layout with the views arranged for the keyboard shown (for instance a new RelativeLayout) that overlays your standard layout. Set it's visibility to GONE. Then when you detect the event that shows the keyboard hide the current view and show the alternate one
I suppose you could also use a ViewSwitcher

If you are using both at the same time then it doesnt work.Set the attribute android:windowSoftInputMode="adjustPan" only.That should work.

Related

Android EditText click, keyboard scroll to different view

I have an EditText. When I click on it, the input keyboard shows up with the EditText directly above it. I want the keyboard to show up a little bit further down at another View, as if the keyboard is focusing on that. Is there a way to handle this?
My use case is I have two EditTexts and a Button in vertical LinearLayout. I want it so that when I click on either of the EditTexts, the keyboard will popup and still show all three Views.
Best practice, you won't want that, i.e showing all views while the keyboard is showing. This will force android to squeeze the views when there isn't enough space.
Best option is try adding paddingBottom to your EditText an example being android:paddingBottom="15dp" This should align the keyboard 15 pixels below your EditText.
You could also use ScrollView as suggested above which allows android to auto handle vertical scrolling for you.

how to add search result on top of other views

I have an EditText in my layout which is used to get the search query from the user. I want to show a LinearLayout bellow it when user enters some characters and fill it with the results (This layout should appear after entering at least N characters). But I don't know how to show this layout?
I thought of putting the whole layout shown in the activity inside a FrameLayout and add the view when required, but there will be two problems:
The view will be added on the top left of the screen.
If I want to move it with adding some padding to it, all the area will correspond to the click event.
To explain what I want more, please take a look at this:
I hope this link will help you, you need to use AutoCompleteTextVIew
http://www.javatpoint.com/android-autocompletetextview-example
https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html
These is two approaches for your case.
Use AutoCompleteTextView
Use android-popupwindow.
The former is easier and more acceptable, however if your want to customize the layout of the resulting search, for example arranging them in a gird view, you may what to use the latter option.
Although, AutoCompleteTextView internally uses the latter option.

How to add a Layout

Hello I want to add a LAyout to my Activity.
I have a FrameLayout where I add a SurfaceView so far.
Now I want to add another Layout as a menu over it so when I click a Button on my Surface View I set it to be Visible.
This layout should contain one Textview and should be scrollable
1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Strings dynamically
2: How can I achieve this in Code?
It should be:
Scrollable.
Should be a certain Size: Half of the screen width and half of the screenHeight
So it also should be at the position screenWidth/4 and screenHeight/4
To achieve this I can set these parameters inside my mainThread that is attached to the surfaceview so I have the parameters needed allready in Pixel format that's no Problem.
It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.
So it should go like this:
User taps the button to display the menu
Now the User can scroll through the Menu
When he presses the Backbutton or outside of the View It should close itself
When there is a new Text that should be displayed it should be attached to the layout to be ready to be displayed at the next time the user clicks the button again
Thank you
1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Textviews dynamically
That sounds good to me, you can go with either ListView or RecyclerView. You are basically not adding TextViews dynamically, you create an adapter that will do handle creating and recycling of views for you.
2: How can I achieve this in Code?
Create a DialogFragment, it's the best candidate for such dialogs with logic. Its lifecycle is handled via FragmentManager, so you won't have issues on screen rotations and so on. It allows you setting whatever layout you need just like any other Fragment. It will be placed in the center for you, so you don't have to handle that manually. Just set the size of the dialog you want and it will look perfect.
It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.
I don't really get this one. When user touches outside, do you need to lose the focus but the dialog should not be closed? If yes, then this is already answered here:
Allow outside touch for DialogFragment
If the dialog should be closed, you don't have to implement anything, it works like that by default.

Nested text view in android,with dynamic content

I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.

android how to hide a edittext and reclaim the space

I have a UI that has a handful of text entries that might be needed by the user. The users selects the type of entry from a spinner. when the selection is made I change the visibility of some edittext controls and change the label that goes with it.
The problem is the space where the edittext was is now blank and the screen layout looks screwy.
I put all of this in a table, hoping I could hide a row, but that didnt help either.
Any ideas short of make a new class for each one?
Instead of setting the visibility to View.HIDDEN, set it to View.GONE. From the description for View.GONE:
This view is invisible, and it doesn't
take any space for layout purposes.
Use with setVisibility(int).
just make sure u use SetVisibility(View.GONE)

Categories

Resources