CharSequence类型
这是一个接口,代表的是一个有序字符集合,这个接口包含的方法有:charAt(int index),toString(),length(),subSequence(int start,int end).
这里需要说的一点就是,对于一个抽象类或者是接口类,不能使用new来进行赋值,但是可以通过以下的方式来进行实例的创建:
CharSequence cs="hello";
但是不能这样来创建:
CharSequence cs=new CharSequence("hello");
下面来看看一个例子:
TextView tv;    //声明一个TextView类型的变量tv
CharSequence cs;    //声明一个CharSequence类型的变量cs
String str;    //声明一个字符串类型的str变量
cs=getText(R.string.styled_text);    //其实这里使用的this.getText()方法,即指定上下文的方法
tv=(TextView)findViewById(R.id.styled_text);    //通过给定的id将tv与对应的组件联系起来
tv.setText(cs);        //使用这句代码来设置tv的显示内容

str=getString(R.string.styled_text);
tv=(TextView)findViewById(R.id.plain_text);
tv.setText(str);

Context context=this;    //这里使用了Context类型的变量context,指定为当前上下文
Resources res=context.getResources();        //定义一个Resources类型的变量res,并给它赋值
cs=res.getText(R.string.styled_text);        //获得R类中指定变量的值
tv=(TextView)findViewById(R.id.styled_text);    //同上
tv.setText(cs);            //设置值

原文链接:http://www.cnblogs.com/zhangzhifeng/archive/2012/03/06/2382034.html

更多相关文章

  1. Android(安卓)AsyncTask几个注意事项
  2. 【Android(安卓)Developers Training】 86. 基于连接类型修改您
  3. phonegap3.0 安装使用
  4. Mac OS X下设置android NDK的环境(详细实测有图)
  5. Java后台解析android端发送的JSON字符串
  6. Android官方开发语音--Kotlin
  7. 如何配置android adb環境變量
  8. (一)、Kotlin学习
  9. (二)Android系统基础-1 APP类型简介

随机推荐

  1. Android布局优化之merge(二)
  2. Android中listview的一些样式设置
  3. Android上替代SQLite的选择:Realm
  4. Android性能:内存篇之内存优化
  5. 最强 Android(安卓)Studio 使用小技巧和
  6. mac开发android 安卓真机调试解决方案
  7. 移动5年 Android生态系统的演进
  8. Android,谁动了我的内存(1)
  9. Android之在GEC210板上点灯。
  10. 《Android技术内幕:系统卷》