Android开发便签3:TextView的自动检测文本中的超链接和自动补全
2010-07-01 15:12:00 来源:WEB开发网在Android中,TextView的一些应用小例子:
Java代码
package com.andy.android;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
/**
* TextView 应用例子
* @author Andy.Zhang
*
*/
public class TestTextView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//1、自动检查超链接
TextView tv = (TextView) findViewById(com.andy.android.R.id.textview);
tv.setText("访问我的javaeye博客 http://andyzhchy.javaeye.com/");
Linkify.addLinks(tv, Linkify.ALL);
//2、自动填充
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.auto_complete);
ArrayAdapter
android.R.layout.simple_dropdown_item_1line,new String[]{
"aa", "ab", "bc", "de", "ac","aab"
});
autoCompleteTextView.setAdapter(arrayAdapter);
}
}
package com.andy.android;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
/**
* TextView 应用例子
* @author Andy.Zhang
*
*/
public class TestTextView extends Activity {
/** Called when the activity is first created. */
更多精彩
赞助商链接