android:labelFor="#+id/tip10et"
android:labelFor="#+id/tip15et"
android:labelFor="#+id/tip20et"
it is showing error android:labelfor is already specified for one text field
labelFor is an accessibility attribute.
If you have a textview that serves at the label for another field ( say an edittext )
you can reference the id of the edit text in the labelfor of the textview.
android:labelFor
Specifies the id of a view for which this view serves as a label for accessibility purposes. For example, a TextView before an EditText in the UI usually specifies what infomation is contained in the EditText. Hence, the TextView is a label for the EditText.
You can't do that as is. You should use multiple label views, each one should have an android:labelFor to their respective labeled View.
BTW: Could use the same string resource for all of them.
Example (minimalist)
<ImageView android:id="#+id/img1"/>
<TextView android:text="#string/sametext"
android:labelFor="#id/img1" />
<ImageView android:id="#+id/img2"/>
<TextView android:text="#string/sametext"
android:labelFor="#id/img2" />
<ImageView android:id="#+id/img3"/>
<TextView android:text="#string/sametext"
android:labelFor="#id/img3" />
Related
I have simple Login page with some textview and edittex and i set static text to textview and hint to edittext from string.xml working fine.
But Now
i am receiving that strings(which i set form stirng.xml as i explained above) form webservices and i have to set webservice string.
Issue is i didn't set any id to that login screen elements(edittext and textview).
Update
I have AppCompatTextView like below in my XML
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_20sdp"
android:gravity="center"
android:text="#string/login_text_welcome"
android:textColor="#color/colorTextLightGrey"
android:textSize="#dimen/textview_size_medium"
android:textStyle="bold" />
I want to settext to above AppCompatTextView without ID.
Is it possible to setText to textview and edittext without setting any id?
You can use findViewByName rather than findViewById and then continue with your code.
Just include android:id="#+id/textView1 in your XML to set ID of an element.
Here's the code for my EditText element:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text=""
android:id="#+id/myTextEdit"/>
The entire app builds and I'm not using this element in code yet, but when it shows up on the screen I cannot type into the element.
This EditText element will not accept text any time I try to type into it.
Do you know why?
The entire reason it fails is because the EditText element is already selectable.
For some reason adding the following property causes the element to be uneditable:
android:textIsSelectable="true"
I removed the property from the layout and I could type text into the element.
What does it mean to set the android:text attribute of a view in a layout xml file to something like #+id/xyz. An example can be found at https://github.com/freezy/android-xbmcremote/blob/master/res/layout/actor_item.xml
Relevant code copied here:
<TextView
android:text="#+id/actor_name"
android:id="#+id/actor_name"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="#+id/actor_role"
android:id="#+id/actor_role"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
That doesn't make much sense. According to documentation what you assign to android:text must be a string value:
Must be a string value, using \\; to escape characters such as \\n or \\uxxxx for a unicode character.
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
Values of #id are integers.
"#+id/id" means you are giving a unique name or id for textview which will help to identify that textview and android:text is like body of the textview u can give anything which u want to display.
"android:text" requires to set String to it. It's the text that will appear in the TextView.
You can either use a plain string or use #string to extract the string from res/values/strings.xml
<TextView
android:text="#string/actor_name"
android:id="#+id/actor_name"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
"#+id/id" is a kind of action that tells the android framework to create an id. The plus symbol, +, indicates that this is a new resource ID and will be created if doesn't exist.
please visit http://developer.android.com/guide/topics/ui/declaring-layout.html#id
The plus (+) sign just indicates it that the ID should be created if it is not under existence at the moment.
It is a general practice to use #+id/something when defining a new View in a layout, and then later use #id/something to reference the View from another part of the layout (say, in any RelativeLayout ) or R.id.something to reference it from our java code.
<EditText
android:id="#+id/drawer_search"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:background="#color/white"
android:drawableLeft="#android:drawable/ic_menu_search"
android:hint="#string/drawer_search_hint"
android:imeOptions="actionSearch"
android:maxLines="1"
android:textColor="#color/dark_blue"
android:textColorHint="#color/dark_blue"
/>
So... all of the attributes work except imeOptions and maxlines. I want the text view to be only one line and the keyboard to not have a return key to go to the next line. It needs to submit/search what ever is in the text view.
So this is the text view. cropped for space.
If you press enter/return it goes to the next line(which there should only be one line).
Why isn't the textview using all of the attributes?
Is there a better way to make it so the keyboard's return button is a submit button rather than next line?
The layout file is declared like this.
View headerRoot = inflater.inflate(R.layout.drawer_header, null);
Attribute android:maxLines corresponds to the maximum height of the EditText or TextView. Use android:singleLine=true for one line input.
How can I set the following two properties for a text field in Android:
(Property 1) How can I set a text field that contains some text like "Enter a number" but when it is clicked the text field automatically becomes empty?
(Property: 2) Suppose I have two text fields in my application. My first text field only accepts integers and the second text field accepts text like "name, address" etcetera. But by mistakenly I enter some text like "apple" or "ball" in my first text field that only accepts numbers.
How can I set my first text field so that when I click on the second text field my first text field should show a toast message or change the color of inputed data to indicate invalid input?
For your first question...
How can i set a text field that contain some text like "Enter a number" but as we click on the text field the text should automatically remove from the text field get become empty.
You are looking for the hint property that the EditText view has. Read more here: http://developer.android.com/reference/android/widget/TextView.html#attr_android:hint
For the second question, you don't need to go through all that trouble. Just set the inputType property for EditText. This will force the keyboard (virtual or physical) to only use either strings or numbers depending on what you specify the input type to be. Read more here: http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
Property 1) You can do this by adding a ht to the EditText:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Your text here"
/>
Property 2)
for Name:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Your text here"
android:inputType="textPersonName"
/>
for Number:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Your text here"
android:inputType="number"
/>
Have a look here for all parameters.
Check out the setError() method fot the 2nd issue.