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

  • 相关阅读:
    进阶系列(8)——匿名方法与lambda表达式
    进阶系列(3)—— 序列化与反序列化
    进阶系列(4)——扩展方法
    数据库设计开发规范
    .Net 项目代码风格
    用JS获取地址栏参数的方法(超级简单)
    Ajax轮询 select循环输出
    【Jquery】jquery刷新页面(局部及全页面刷新)
    网页上 滚动代码 最简单的
    eazyui 或bootstrap table表格里插入图片,点击查看大图
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120074.html
Copyright © 2011-2022 走看看