what does maxLength="#length" means in an xml android layout file? - android

Does someone knows what the #attribute value means in this xml file?
<EditText
android:id="#+id/firmaText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:ems="8"
android:textColor="#color/black"
android:textSize="14sp"
android:paddingLeft="5sp"
android:inputType="textPassword"
android:lines="1"
android:maxLength="#{longitud}"
android:text="#{pin}"/>
I know the meaning and use of the maxLength attribute, the problem is the value it have.
I also think is a kind of preprocessing, but, it doesnt compile...

Solved, it was a syntax error of the library.
Thanks to all.

android:maxLength
Set an input filter to constrain the text length to the specified number.
Must be an integer value, such as "100".
For Example : android:maxLength="6" limits the length of the EditText to 6 characters.
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.

Related

How can I set a multiline TextView?

I have a TextView in Android that shows the information that it's retrieved from a database so I don't know how much lines will be used for show the information.
This is my TextView:
<TextView
android:id="#+id/lblInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:inputType="textMultiLine"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
And what I tried it's to put the property android:inputType="textMultiLine" but it gives to me an advice:
Attribute android:inputType should not be used with <TextView>: Change element type to <EditText>?
I searched on Internet but in all answers they know the maximum lines that they need, so they use the property android:maxLines="the maximum of lines they want" or android:lines="the total of lines that the TextView has" but I don't want that because I don't know how much lines I will have in my TextView.
How can I make a TextView with an undefined number of lines?
Thanks in advance!
Use following xml. Hopefully it will work.
<EditText
...
android:inputType="textMultiLine"
/>

meaning of setting android:text to #+id/xyz

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.

disable "spell checking" on textView

This is more a 'is there a more appropriate way' question as I have found a work around.
Some of my table headers are being picked up as spelling errors and underlined in red. Of course, that is not what I would like to see. I have found that using
android:inputType="textNoSuggestions"
does disable the spell check markings. I find it odd (bug?) that this is necessary as the docs state:
inputType: The type of data being placed in a text field, used to help
an input method decide how to let the user enter text.
and there is no input associated with just textView. So is this the only/more appropriate way of avoiding the spell check and also, is this a bug that it is spell checking non-input fields?
UPDATE: per request this is sample xml
<TextView
android:text="ID#"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:typeface="monospace"
android:textSize="14sp"
android:digits="4"
android:textAlignment="gravity"
android:layout_weight="5"
android:gravity="left"
android:singleLine="true"
android:phoneNumber="true"
android:inputType="textNoSuggestions|none">
</TextView>
First, I would try removing the android:digits, android:phoneNumber, and android:inputType attributes.
All of those are more intended for use with fields that allow input (such as EditTexts). It also doesn't look like you are using the android:digits attribute correctly, as the string you provide defines the only allowable characters.
In essence, this combination of attributes is telling Android that your TextView accepts input in the form of telephone numbers that contain only the number 4, that this TextView doesn't accept input of any type, and Android should not provide spellcheck suggestions.
If you are setting the content of the TextView yourself, there really is no reason to try to restrict the content of the TextView with flags such as android:phoneNumber since you are the one controlling that.
I know this is an old thread but removing the following from content XML worked for me:
android:autoText="true"
On later android studio versions try:
android:autoText="true"
inside of the (or any input) in the xml.
On newer versions try:
android:inputType="textNoSuggestions"

This text field does not specify an inputType or a hint

I get the warning, "This text field does not specify an inputType or a hint" When I modify a copy of a tutorial code (below)
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:layout_weight="1" />
This works fine, and the warning only comes up if a new blank line is created
I've modified it for a friend with several comments lines explaining what each part of it does however, whenever i add in an extra line in the above (Even a blank line, in this case it's a comment line) I receive the above error
<!--edit text creates a text input box-->
<EditText android:id="#+id/edit_message"
<!-- edit_message is a variable, defined in strings.xml-->
<!-- determines the width of the textField, in this case 0dp means "however long the text is" IE: it will grow to fit however many characters the user types -->
android:layout_width="0dp"
<!-- determines the height of the Text Field -->
android:layout_height="wrap_content"
<!-- The hint is the default value for the text field, it calls on the variable edit_message defined in strings.xml-->
android:hint="#string/edit_message"
<!-- Weight means how much the screen the text field can take up, in this case, the ratio is 1:1 so it can take up however much room is needed, However if a different variable also had the weight of 1, the ratio would be 1:2 and each could take up half the screen -->
android:layout_weight="1" />
Without the comments, the warning is not there
The Reason for this warning is that you haven't set the inputType for this editText. Add the following line:
android:inputType="text"
So it should look like this:
<EditText android:id="#+id/edit_message"
android:inputType="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:layout_weight="1" />
And the warning is gone.
Logically you should get warning in the line
<EditText android:id="#+id/edit_message"
and an error in the next line.
Reason:
When you are placing comment tags, then the closing tag of comment is considered as the illegal closing tag for EditText. So you should even get the following error
Element type "EditText" must be followed by either attribute specifications, ">" or "/>".
and because of the above error the remaining code is not executed and thus you get a warning
This text field does not specify an inputType or a hint
even though android:hint attribute exists in your code.
I just run your code and got my app running properly, when i added the comment it crashes, then i realized that you should not comment inside your XML , it is a principle of XML.
I suggest you to read this article explaning what is a well formed XML and how to comment xml in the right way http://webdesign.about.com/cs/xmlinformation/ht/htcommentxml.htm
Also here has been a discussion about this particularly subject and has been solved as well.
https://stackoverflow.com/a/2073162/2069737
Hope it helps you.

Why does TextView in single line elipsized with "end" show boxes?

I'm using a TextView in Android, what I want to show 1 line in TextView ending with ". " but this give [] type box at the end. I don't know why? I just want to remvoe this box and only to show text ending with "... "
Update code for the list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="85dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:cacheColorHint="#4C7B8D"
android:background="#4C7B8D">
<ImageView
android:id="#+id/videoListImage"
android:src="#drawable/audio_thumbnail60x60"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:layout_width="75dp"
android:padding="4dp"
android:background="#color/light_gray" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/next_arrow"
android:orientation="vertical"
android:gravity="center_vertical"
android:paddingLeft = "5dp">
<TextView
android:id="#+id/row_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/app_background_color"
android:textSize="18sp"
android:ellipsize="end"
android:maxLines="1" />
<TextView
android:id="#+id/row_dis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/color_black"
android:layout_marginRight="2dp"
android:textSize="15sp"
android:ellipsize="end"
android:maxLines="1" />
<TextView
android:text="$7.50"
android:id="#+id/audio_price_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="#color/color_white"
android:textStyle = "bold"
android:paddingLeft = "12dp"
android:paddingRight = "12dp"
android:background="#drawable/blue_round_cornor_background" />
</LinearLayout>
<ImageView
android:id="#+id/next_arrow"
android:src="#drawable/next_arrow"
android:layout_toLeftOf="#+id/saved_purchased"
android:scaleType="fitXY"
android:layout_height="25dp"
android:layout_width="18dp"
android:layout_centerVertical="true"
android:visibility = "gone"/>
<ImageView
android:id="#+id/saved_purchased"
android:layout_alignParentRight="true"
android:layout_alignParentTop ="true"
android:scaleType="fitXY"
android:layout_height="25dp"
android:layout_width="25dp"
android:layout_marginRight="2dp"/>
</RelativeLayout>
Here is the images of "next_arrow"
Here is the code I am using the getView() in adapter.
String discription = listData.getDescription();
if (discription != null && discription.length() > 0) {
if (textViewDis != null) {
textViewDis.setTypeface(titleFont);
Log.e("data", ""+discription);
discription.replaceAll("\r\n", "");
textViewDis.setText(discription);
}
}
Here is the actual String of description to be display.
Andrew and Stephanie Tidwell candidly share their success story in this business. This story will help everyone listening realize that no one is perfect, even in a second generation business. This is a streaming audio file.
Still have some issue? I can update question more.
Quoting myself from one of my books:
Android's TextView class has the built-in ability to "ellipsize" text,
truncating it and adding an ellipsis if the text is longer than the available
space. You can use this via the android:ellipsize attribute, for example.
This works fairly well, at least for single-line text.
The ellipsis that Android uses is not three periods. Rather it uses an actual
ellipsis character, where the three dots are contained in a single glyph.
Hence, any font that you use that you also use the "ellipsizing" feature will
need the ellipsis glyph.
Beyond that, though, Android pads out the string that gets rendered on-screen, such that the length (in characters) is the same before and after
"ellipsizing". To make this work, Android replaces one character with the
ellipsis, and replaces all other removed characters with the Unicode
character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). This means the
"extra" characters after the ellipsis do not take up any visible space on
screen, yet they can be part of the string.
However, this means any custom fonts you use for TextView widgets that
you use with android:ellipsize must also support this special Unicode
character. Not all fonts do, and you will get artifacts in the on-screen
representation of your shortened strings if your font lacks this character
(e.g., rogue X's appear at the end of the line).
I have bumped into the same problem when was trying to use custom "MetaPro-Medium.otf" as font for TextView with a
android:singleLine="true".
The box at the end of the string was really annoying.
I found no way how to solve this problem in Android, but at the same time found following work around.
I have installed "FontLab Studio v5.04"
Opened my font
Selected one of symbols I was not going to use
Menu->Glyph->Rename Glyph
Changed the name and unicode index from it`s original value to "FEFF" (Thank CommonsWare)
Double click on selected symbol and then remove all lines this symbol was created from.
Menu->File->Generate Font->save as type otf
As a result I got updated font and problem gone away.
Arslan, your layout is working fine in my case, I have tested the same with:
<TextView
android:id="#+id/row_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="18sp"
android:ellipsize="end"
android:maxLines="1"
android:text="This is the demo testing demo testing This is the demo testing demo testing"/>
... and getting the exact output as you want "one line ended with ..." and box should be removed. So I think there may be a something wrong with any character or text you are setting.
I face the same issue (show boxes([])) for some special symbols when I try to show content which is coming from webservice url even, I don't use android:ellipsize. then I replace code from
textview.settext(content);
to
textview.settext(Html.fromHtml(content));
working fine.
Actually I was running into this issue and instead of changing the font or using setText I just added scrollHorizontally as false and it fixed the extra box character
android:singleLine="true"
android:scrollHorizontally="false"
android:ellipsize="end"
There was a similar problem which i was facing in my project where in i was using a font type for the text view. few font types have these problem of making the ... appear as [] at the last. The problem would be solved if u try changing the font.

Categories

Resources