Android Programming Development TextView Control usage (2 methods) _android

Source: Internet
Author: User

This example describes the TextView control usage of Android programming. Share to everyone for your reference, specific as follows:

Here we will talk about the use of commonly used controls.

The same is true in most of the future chapters, and we will talk specifically about the use of certain controls. Because as long as these controls are grouped together, they are an application.

Okay, let's just see how this control is used.

Careful students will find, in fact, the content of this control is defined in the values folder inside the Strings.xml.

So we just need to add a code to it:

Copy Code code as follows:
<string name= "Test" >welcome to joven\ ' s blog</string>

Then bind to the control

<textview
    android:layout_width= "wrap_content"
    android:layout_height= "wrap_content"
    android:text = "@string/test"/>

It's OK. Let's look at the effect.

In fact, there is a second method, but also the most commonly used method, is dynamically acquired.

Let's add an ID to TextView and write it in Main.xml:

<textview
    android:id= "@+id/tv1"
    android:layout_width= wrap_content "android:layout_height=" Wrap
    _content "
    android:text=" @string/test "/>

And then dynamically bind in the activity, which is written in the Testdemo.java:

Package Com.example.testdemo;
Import Android.os.Bundle;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.widget.TextView;
public class Testdemo extends activity {
  private TextView TV;
  @Override
  protected void onCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.main);
    A control TextView with ID TV1 in the bound view.
    tv= (TextView) Findviewbyid (R.ID.TV1);
    Dynamically set the content of the control.
    tv.settext ("welcome!");
  }


All right, let's see the effect:

Above the priority level, the program loads the resource file before loading the activity. So the latter's settings will overwrite the former.

I hope this article will help you with the Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.