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

  • 相关阅读:
    零零碎碎
    MFC入门--显示静态图片及调用本地软件
    Python版本OpenCV安装配置及简单实例
    用星星画菱形--Java
    pycharm IDE在导入自定义模块时提示有错,但实际没错
    Cmd使用方式--命令行运行程序
    cv2 & PIL(pillow)显示图像
    C++命令行多文件编译(g++)
    MNIST多图显示--Python练习
    visual studio 2017--括号自动补全
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120074.html
Copyright © 2011-2022 走看看