zoukankan      html  css  js  c++  java
  • 更改显示TextView显示

    首先打开”main.xml”布局文件
    image
    ,添加TextView命名为tvHelloWorld:保存。
    <?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:id="@+id/tvHelloWorld" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    </LinearLayout>

    这时候Eclipse编译器会自动生成TextView代码,打开R.java文件
    image

    可以看到

    /* AUTO-GENERATED FILE.  DO NOT MODIFY.
     *
     * This class was automatically generated by the
     * aapt tool from the resource data it found.  It
     * should not be modified by hand.
     */
    
    package idroidgame.ActivityTest;
    
    public final class R {
        public static final class attr {
        }
        public static final class drawable {
            public static final int icon=0x7f020000;
        }
        public static final class id {
            public static final int tvHelloWorld=0x7f050000;
        }
        public static final class layout {
            public static final int main=0x7f030000;
        }
        public static final class string {
            public static final int app_name=0x7f040001;
            public static final int hello=0x7f040000;
        }
    }

    然后在ActivityText.java中输入

    package idroidgame.ActivityTest;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import android.widget.TextView;
    public class ActivityTest extends Activity {
    	TextView tv=null;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            tv=(TextView)this.findViewById(R.id.tvHelloWorld);
            String str="设置TextView的值";
            tv.setText(str);
        }
        
    }

    TextView的setText有很多重载方法;

    image

  • 相关阅读:
    匿名方法
    Webform 服务器控件与客户端控件以及验证控件
    MVC分页方法+js
    MVC注册验证:js方法(jQuery)
    MVC新闻提交小练习+Session登录提交练习
    MVC省市区三级下拉菜单联动
    MVC三级下拉菜单
    MVC操作SQL数据库增删改查
    C#注册机与绑定软件(转发自:韩兆新的博客园的C#学习笔记——软件注册与注册机)
    报表
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120074.html
Copyright © 2011-2022 走看看