Adding a Text Field

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 <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 these attributes:
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 and android: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 the EditText element would fill the screen, because it would match the size of the parent LinearLayout. 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. 
 

5 comments:

  1. Amazing! thank you, I'm learning so much

    ReplyDelete
  2. I enjoyed reading this detailed and engaging article. The content is well structured and easy to understand. Great work on this post.online business analyst course

    ReplyDelete
  3. Great post! An OpenShift online course is a flexible way to learn Kubernetes, container orchestration, and CI/CD pipelines. With hands-on labs and real-world projects, it helps learners gain practical skills to deploy, manage, and scale cloud-native applications efficiently.openshift online course

    ReplyDelete
  4. Learn boomi programs help learners understand cloud integration and application connectivity using Dell Boomi technologies. This learn boomi training covers integration processes, API management, workflow automation, and deployment concepts. Students gain hands-on experience through practical assignments and real-time projects. The training prepares learners for careers in cloud integration and enterprise application development.

    ReplyDelete