Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Working with TextView and EditText in Android Applications

This article will explain the process to come up with huge number of text controls in the Android Application and will also cover the basics of EditText.

Introduction

Let us see with the medium of this article how to create different text controls in the Android application. Also we will be able to configure, style, and manipulate the controls in lot number of ways. There are lot of attractive features present that can be used within the application so as to modify.

  • The style
  • Position

Basically, there are four different types of Text Control's in Android:

  • TextView
  • EditText
  • AutoCompleteTextView
  • MultiCompleteTextView

TextView

This TextView has a very attractive attribute that automatically allows it to create a link which is based on the text content. In case we have text as URL or e-mail address, the default intent is launched on accessing the textview by the user irrespective of it being the web browser or a dialer.

Android: autoLink is the property that we use for the linking.

Let us go step by step to understand the concept of TextView

Step 1: Create a new android application

Illustrates the creation of new android application

Figure 1: Illustrates the creation of new android application

Step 2: You need to navigate to Main.axml in Resources/Layout and do the changes as shown in the figure below:

Illustrates modifications in Solution Explorer

Figure 2: Illustrates modifications in Solution Explorer

Listing1: android:text propertyinsert text in normal text view

<?xml version=”1.0” encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text=" create different text controls in the Android application. Also we will be able to configure, style, and manipulate the controls in lot number of ways we have so many useful attributes which we can use within the application to change the style, position etc."
      android:textColor="#ff0fffff"
    />
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text=" This TextView has a very attractive attribute that automatically allows it to create a link which is based on the text content. In case we have text as URL or e-mail address, the default intent is launched on accessing the textview by the user irrespective of it being the web browser or a dialer."
      android:textColor="#ff000fff"
    />
</LinearLayout> 

In the code displayed above, we see the android:text property that is used to insert the text in normal textview. The other property android:textColor is made use of to change the colour of text.

Output

Illustrates the Output of Listing 1

Figure 3: Illustrates the Output of Listing 1

As mentioned above, android:autoLink property has been made use of in conjunction with textview to identify if it is a web, email, phone and address details.Example, if we write any website url or let us say any phone number in textview and android:autoLink="all" property was not the one that is used textview as compared to the URL that displays a simple text. Also if I utilize android:autoLink="all" property, then we can see the text as a clickable one.

Listing 2: Modifying the Main.axml to see the effect of android:autoLink="all" property

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="You can create a number of different Text controls in your Android application."
    />
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="http://www.mrbool.com/"
      android:autoLink="all"
    />
  <TextView 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="5 777-333-0000"
      android:autoLink="all"
    />
</LinearLayout>

Output

Illustrates the Output of Listing 2

Figure 4: Illustrates the Output of Listing 2

Introduction to EditText

EditText nothing but a subclass of the TextView class, that is functionally rich and alterable. Also it enables users to edit text same as the TextBox.

Steps to understand EditTex:t

  • Again Create a new android application
  • Now, one should navigate to Main.axml in Resources/Layout and do the following changes

Listing 3: Modifying the Main.axml to see the effect of autoText, capitalize and password properties

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <EditText
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:capitalize="characters"
     android:autoText="true"
  />
  <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:capitalize="words"
    android:autoText="true"
  />
  <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:capitalize="none"
    android:autoText="true"
  />
  <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:password="true"
  />
</LinearLayout>

We saw three sort of properties autoText, capitalize and password and offers multiple properties such as singleLine and many more.

Conclusion

The article intended to cover the concept of creating text controls and the basics of Edit text property in Android Application.



Software Developer from India. I hold Master in Computer Applications Degree and is well versed with programming languages such as Java, .Net, C and C++ and possess good working knowledge on Mobile Platforms as well.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login