Android学习笔记(二)
2011-11-10 10:13
267 查看
昨天只是打了打基础今天开始翻阅android官方文档,一开始省事下载了一些中文文档观看,但是发现这些文档不全,翻译有些硬伤,譬如说是把表面的意思翻译出来了但是有些可以扩展的知识点没有点明。属性的含义介绍清楚了,但是属性值没有给出,很是纠结,没有办法只能用我那蹩脚的英语去看官方文档,但是还是官方那个文档给出的说明详细,不懂得可以金山来帮忙,俗话说实践才是硬道理,今天把官方文档中的一些我感觉比较有用的例子拿到这里分析一下,(水平有限能力有限,如有不对的地方,还请多多指教。)
案例一:
(extView.BufferType.EDITABLE 和 TextView.BufferType.SPANNABLE
有什么区别呢?我们透过UML瞧一下, Editable 类似于StringBuilder可追加字符,
也就是说getText后可调用append方法设置文本内容。Spannable 则可在给定的字符区域使用样式。有意思的是 Editable 继承了 Spannable 所以具备较多的功能。)
案例一:
ReceiveResult.java
/** * Shows how an activity can send data to its launching activity when done.y. * <p>This can be used, for example, to implement a dialog alowing the user to pick an e-mail address or image -- the picking activity sends the selected data back to the originating activity when done.</p> <p>The example here is composed of two activities: ReceiveResult launches the picking activity and receives its results; SendResult allows the user to pick something and sends the selection back to its caller. Implementing this functionality involves the {@link android.app.Activity#setResult setResult()} method for sending a result and {@link android.app.Activity#onActivityResult onActivityResult()} to receive it.</p> **/ /** 本人翻译如下: 首先该例子展示的是一个activity当他完成搜集信息的工作室怎样向他需要的已经打开的activity的时候发送数据。 这个很有用,例如继承一个dialog类,它可以提供用户选择是发送email和发送图片的选择,当用户选择完毕时,该对话框的activity将用户选择的信息返回给源activity (我理解为能够处理该信息的activity)。 本例子中向我们展示的有:首先案例中有两个activity,一个是提供用户选择信息的activity,另一个是接受结果并对其进行相应的activity,选择信息的activity可以允许用 户选择要做的选择或要发送的信息给处理的activity,实现这个函数包括下面两个(下面的我就不做翻译了,同志们都懂得)贴上源程序: **/
public class ReceiveResult extends Activity { /** * Initialization of the Activity after it is first created. Must at least * call {@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. */ @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); // See assets/res/any/layout/hello_world.xml for this(查看结构文档中的定义内容,关于定义布局什么的都在那里) // view layout definition, which is being set here as // the content of our screen. setContentView(R.layout.receive_result); // Retrieve the TextView widget that will display results.(将TextView Widget放置在面板上) mResults = (TextView)findViewById(R.id.results); // This allows us to later extend the text buffer.(这个可以允许我们稍后继承textbuffer) mResults.setText(mResults.getText(), TextView.BufferType.EDITABLE); // Watch for button clicks. Button getButton = (Button)findViewById(R.id.get); getButton.setOnClickListener(mGetListener); } /** * This method is called when the sending activity has finished, with the * result it supplied. * * @param requestCode The original request code as given to * startActivity(). * @param resultCode From sending activity as per setResult(). * @param data From sending activity as per setResult(). */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // You can use the requestCode to select between multiple child // activities you may have started. Here there is only one thing // we launch. if (requestCode == GET_CODE) { // We will be adding to our text. Editable text = (Editable)mResults.getText(); // This is a standard resultCode that is sent back if the // activity doesn't supply an explicit result. It will also // be returned if the activity failed to launch. if (resultCode == RESULT_CANCELED) { text.append("(cancelled)"); // Our protocol with the sending activity is that it will send // text in 'data' as its result. } else { text.append("(okay "); text.append(Integer.toString(resultCode)); text.append(") "); if (data != null) { text.append(data.getAction()); } } text.append("\n"); } } // Definition of the one requestCode we use for receiving resuls. static final private int GET_CODE = 0; private OnClickListener mGetListener = new OnClickListener() { public void onClick(View v) { // Start the activity whose result we want to retrieve. The // result will come back with request code GET_CODE. Intent intent = new Intent(ReceiveResult.this, SendResult.class); startActivityForResult(intent, GET_CODE); } }; private TextView mResults; }
(extView.BufferType.EDITABLE 和 TextView.BufferType.SPANNABLE
有什么区别呢?我们透过UML瞧一下, Editable 类似于StringBuilder可追加字符,
也就是说getText后可调用append方法设置文本内容。Spannable 则可在给定的字符区域使用样式。有意思的是 Editable 继承了 Spannable 所以具备较多的功能。)
相关文章推荐
- Android学习笔记(十七)——使用意图调用内置应用程序
- Android学习笔记--环境搭建
- Pro Android学习笔记(一五八):联系人API(1):账号
- Android学习笔记二 Intent跳转界面
- Android学习笔记の一
- Pro Android学习笔记(一六一):联系人API(4):读取整合联系人
- android学习笔记之下拉动态弹出图标菜单的实现
- Android学习笔记——关于onConfigurationChanged(转)
- Android学习笔记(三五):再谈Intent(下)-一些实践
- Android学习笔记(五十):声明、请求和检查许可
- Android学习笔记--读取网络图片
- 数据存储之SharedPreferences存储——第一行代码Android学习笔记
- Android学习笔记(19)————实现一个记住密码的Android登陆界面 .
- Android学习笔记(5)——保存文件到sd卡
- Pro Android学习笔记(三三):Menu(4):Alternative菜单
- Android学习笔记—第二章 Android四大组件
- Android学习笔记——自定义Loader
- Android学习笔记(八)
- Android学习笔记--HttpURLConnection和HttpClient的使用
- Android学习笔记(2):带预览的图片浏览器(GridView、ImageSwitch以及SimpleAdapter)