Whats up Geeks,
In the last tutorial we have learned Creating Grid View.
Going forward, in this tutorial we are going to learn Adding a Text Fields.
First of all what is Text Fields?
And the answer is "A text field allows the user to type text into your app. It can be either single line or multi-line. Touching a text field places the cursor and automatically displays the keyboard."
How to create a Text Fields?
To create a user-editable text field, add an
Like every
Below is the declaration of <EditText> it inside the
Every resource has a corresponding resource object defined in our project's
We can use the object names in the
The SDK tools generate the
About these attributes:
In the last tutorial we have learned Creating Grid View.
Going forward, in this tutorial we are going to learn Adding a Text Fields.
First of all what is Text Fields?
And the answer is "A text field allows the user to type text into your app. It can be either single line or multi-line. Touching a text field places the cursor and automatically displays the keyboard."
How to create a Text Fields?
To create a user-editable text field, add an
<EditText>
element inside the <LinearLayout>
.Like every
View
object, you must define certain XML attributes to specify
the EditText
object's properties.Below is the declaration of <EditText> it inside the
<LinearLayout>
element:<EditText android:id="@+id/edit_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" />
About resource objects
A resource object is simply a unique integer name that's associated with an app resource, such as a bitmap, layout file, or string.Every resource has a corresponding resource object defined in our project's
gen/R.java
file.We can use the object names in the
R
class to refer to our resources, such as when we need to specify a
string value for the android:hint
attribute. We can also create arbitrary resource IDs that we associate with a view using the android:id
attribute,
which allows us to reference that view from other code.The SDK tools generate the
R.java
each time we compile our app. We should never
modify this file by hand.android:id
- This provides a unique identifier for the view, which you can use to reference the object
from your app code, such as to read and manipulate the object (you'll see this in the next
lesson).
The at sign (
@
) is required when you're referring to any resource object from XML. It is followed by the resource type (id
in this case), a slash, then the resource name (edit_message
).
android:layout_width
andandroid:layout_height
- Instead of using specific sizes for the width and height, the
"wrap_content"
value specifies that the view should be only as big as needed to fit the contents of the view. If you were to instead use"match_parent"
, then theEditText
element would fill the screen, because it would match the size of the parentLinearLayout
. For more information, see the Layouts guide. android:hint
- This is a default string to display when the text field is empty. Instead of using a hard-coded
string as the value, the
"@string/edit_message"
value refers to a string resource defined in a separate file. Because this refers to a concrete resource (not just an identifier), it does not need the plus sign.
Amazing! thank you, I'm learning so much
ReplyDelete