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.
Related
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
In my app I have a couple of checkboxes, that when checked combine the first part of an edittext. In the same edittext I would like to allow the user to append some text, while disallowing to delete the built text.
This is how it looks
[This part is build from checkbox combination, and can change in real time][This part is user defined]
Now is there a way to not allow the user to modify the first part of the edittext, but still allow the app to change this text?
You can certainly create a TextWatcher object and add it to your edittext. In your textwatcher, you can store the constant text information in an instance variable. Then, you can fill in the onTextChanged() and afterTextChanged() methods to create the type of behavior you are looking for.
For example, you can check the cursor position (using editText.getSelected()) to see if the user tried to change some of the text that shouldn't be changed-- if they do, then have some code to handle the case.
I know this isn't the best answer, but I don't yet have privilege to make a comment. Hope this helps!
I need help about EditText in android.
In my app i have 2 editText fields. The firs is mandatory to make some calculations, the second is not mandatory it is avalaible only if checkbox is checked. My problem is that i cant make calculations if i don't put some value in secont EditText field.
How can i disable it (out of function) the second field, and to be enabled only if checkbox is checked ?
You can disable your EditText by calling edittext.setEnabled(false) (enable it by calling the same method with true) and you can get the status of your checkbox by calling checkbox.isChecked(). Just combine the two to achieve what you want.
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".
I'm creating a login form for my Android app, i make a single layout for both create account and login, on button click i want to change edit text hint property from 'enter user name' to 'Re enter username' and also want to change other edittext password property to true can any one help me how to change both property from code dynamicaly i saw all methods of edit text but not found any clue.
You can use .setHint() method on either your TextView or EditText.
http://developer.android.com/reference/android/widget/TextView.html#setHint(int)
EditText is an extended class of TextView. Hence, most of the methods (if not all) of TextView will work well with EditText.
You want to look at its parent class TextView, specifically setHint and setInputType.