Clear Focus of EditText when clicking on a button - android

Everyone,
I would like to achieve the following in my Android App:
I would like to create a view in which there are several input fields.
An associated toolbar contains a save button.
If I have the focus in an EditText field and then press Save, I want the value of the edit field to be taken before saving.
So far I have created a workaround where a method resetFocus() is called before saving which does the following:
if (binding.volume.hasFocus()) binding.volume.clearFocus();
Is there a clean way to implement the request without such a help method?
Thx for you help

Related

AutoFill EditText Android

I'm trying to create a search bar like.
I have to use a particular autofill, infact I can't use a dropdowns menu.
For example if I write Noce the edittext will have to suggest Nocera in the same editText, like this.
but if the user write something else the pointer have to the end of the typed text (in this case Noce) and the hint have to disappear.
Is there some library that allows me this?
Thanks for the help.
There's this library that will fulfill some of your requirement called Auto Fill EditText
Finally I have solved this using two EditText in the same position. The first one is a normal editable EditText, the second one is not editable from the user but is used to show the hints programmatically.

Enable/Disable EditText in Android

I am new to Android and I want to ask from you people. that I have a Android Activity named as Account Page, It shows the user his/her registration data. The Activity contains editable fields (EditText).
I want that initially, all The EditTexts are disabled and get enabled when I click on the Edit TextView (Button?). When the fields are enabled, the Edit TextView should read 'Apply'. When I click on 'Apply', then data should be modified, and the fields and Button restored to the initial state.
I am using this implementation using SharedPreferences in Android.
Kindly tell me how I can achieve this.
For disabling edittext: How to disable edittext in android
disable edittexts in onCreate() method or disable it using XML attribute.
In onClick method of Edit textview, enable all edittext and change text of textview to Apply.
In onClick method of Apply textview, first check if the text in textview is "Apply" and then update the date and set text back to Edit.
You can achieve this by mimicking the two 'states' of your form using two methods : init() and edit(). In the method init(), disable all fields that you want to disable and set the text of your Button/TextView to 'Edit'.
In the method edit(), enable all the above fields and set the text of your Button/TextView to 'Apply'.
All you need now is to correctly place calls to these methods. I suggest you place calls to init() when your Activity is created and after the user hits Apply.
Add a call to edit() whenever you set the text of your Button to 'Edit'.
I would love if you understood what I'm suggesting and coded it yourself.

android softkeyboard on keypress listener

A newbie on Android. Need an example of how can i use soft keyboard. What i want to achieve is on Button click a keyboard should appear and a TextView should be populated with every keypress event with the key pressed. When i try to do so i get NullPointerException. I couldn't understand what exactly the reason could be. Some place i read to initialize my view with onkeylistener, but i couldn't get where and how to do it. Please explain me the steps to implement it. Would be very helpful.

Android how to get Suggested strings array of the TextEdit

Is there a way to get an array of the suggestions strings which are shown when you typing in EditText? The problem is I have an EditText and in case of user use "Show Suggestions" option the result of the string from this EditText is different in case of user pressed, lets say UI button (this is a Button from the layout), and a return button at the soft keyboard. In first case user gets an exact string but in second - it gets corrected (suggested) string even user do NOT select this suggestion. How to solve this problem? How to get from EditText "suggested" string? Do I need to implement my own IME?
Maybe this can help you ? Hello Auto Complete
Or if you want to write one on your own.. Writing your own autocompleteview
Are you trying to disable suggestions or to modify them?
If you want to disable them completely, check this out:
How to disable displaying "suggestions" on the Soft Keyboard

layout having disabled edit text

I am building one app having one list view showing list of users this, when i click on list item it will show me complete profile of clicked user this. I take EditText fields on this layout (i use the same layout to show my own profile which is editable) whose text is filled dynamically(e.g., data of clicked user is filled in this form).Since, it only show me profile of concern user & i not need any editing on user data so i disable editing on these edit text fields by calling this method on each one.
setEnabled(false)
this layout is scrollable and when i scroll this view it enable editing on these edit text field this
How i disable editing on these edit text field...???
Any suggestions please, would appreciated any pointer, sample code to do this
Actually, an EditText is needed when you want to enable user to type some information. To draw the information generated by your application you should use a TextView, which by default does not give the opportunity to change text contexts. Usually, a disabled EditText misleads users, making them feel like they've done something wrong, so try to use proper views for solving common problems. Hope this helps.
You can take TextView instead of EditText as it is a label, and if you still want it to look like edit field. you can use default editfield background by setting background of textView to
#android:drawable/edit_text in xml file.
In XML of editText write android:editable="false".

Categories

Resources