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.
Related
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.
I want to set some text in EditText type fields. I want to do this while loading the activity. And then I don't want user to make any changes to it. Can I set EditText type boxes to non-editable mode? Does there exists any other element which could solve my purpose?
A TextView sounds like what you want; you can call setText() on them.
For EditText itself you could call this version of setText(), and set the buffer type to NORMAL instead of EDITABLE.
there are two options.
setEditable and setEnable. set false in Oncreate.
but in setEditable user can edit text by long click -> paste option.
If you are not taking any input from user in the EditText and it is just used to show some text that is set programmatically at onCreate, then you can use TextView instead. It is more suited for your requirement.
Here is a comparison between EditText and TextView that might be helpful.
Is there any particular reason for you to use a non-editable EditText? In case you absolutely have to use EditText then setting it as non-editable in your code after you set the value will suffice. You can do it in a few different ways, one of them would be setting input type as null in code.
yourEditText.setInputType(InputType.TYPE_NULL);
You can do android:enabled="false" in layout of that activity.
or
editText.setEnabled(false);
I have simple question. I am a new newbie to android. I did got through few tutorials but some responses did not work in my eclipse. I am using version 2.2.
Can we give text view the functionality of edit text of editing?
EditText extends TextView and gives it editable functionality, if you want the EditText to look like TextView, You can change the background and other style properties
User won't be able to type or edit anything in a text view. It is purely for viewing. But you could set values in a text view with user inputs from an edit text.
TextView
Displays text to the user and optionally allows them to edit it. A
TextView is a complete text editor, however the basic class is
configured to not allow editing; see EditText for a subclass that
configures the text view for editing.
You can use EditText for this.
Yes you can make Textview editable, with android:editable="true",
Please check this link for further reference..
http://developer.android.com/reference/android/widget/TextView.html#attr_android:editable
Hope this will help you
Yes, TextView can be edited. Try this:
TextView.setText();
I need to achieve the similar behavior from the image below. I need to add extra static information inside an EditText in android that does not change according to the user's input (except for the character count).
How do I achieve this? As per I see from the focus, the data is inside the EditText and not out, so i believe this is some sort of style or a custom component.
Many Thanks
T
What you could do is make a view group with the text how you want it with an EditText at the top for the user input, then set the background of your view group to android:background="#android:drawable/editbox_background"
use setText() method of EditText with the appropriate BufferType
for the top text, and setHint() for the bottom one.
Is there a way to set the background text of an EditText? for instance, I have a login screen with 2 EditText views, one for username and one for password. I want the text "Username" and "Password" be written inside the EditText, and once the user touches those the text disappears but once user deleted his own entry, text re-appears.
Is there a property for that or should I implement this on my own with events and stuff?
The hint property will take care of that for you.
Use hint property, or setHint method.