本范例以EditView与TextView示范如何在捕捉User键盘输入文字的时实时取得文字,同步显示于Textview,实时输入输出。
package com.chaowen;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Ex04_01 extends Activity {
/** Called when the activity is first created. */
private TextView mTextView;
private EditText mEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView=(TextView)findViewById(R.id.myTextView);
mEditText=(EditText)findViewById(R.id.myEditText);
//设置EditText用onkeyListener来启动
mEditText.setOnKeyListener(new EditText.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
mTextView.setText(mEditText.getText().toString());
return false;
}
});
}
}
//main.xml
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:id="@+id/myEditText"
android:layout_width="149px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="29px"
android:layout_y="33px"
/>
<TextView
android:id="@+id/myTextView"
android:layout_width="135px"
android:layout_height="41px"
android:layout_x="33px"
android:layout_y="106px"
/>
</LinearLayout>
分享到:
相关推荐
汉字 拼音包 Pinyin4J,android AutoCompleteTextView 汉字拼音匹配用到的额拼音包
android中设置字体库 Typeface typeFace = Typeface.createFromAsset(this.getAssets(), "fonts/xx.ttf"); textView.setTypeface(typeFace); textView.setText("帅气");
[Android开发从零开始].4.TextView控件学习
android自定义组合控件
android_api_textview
AndroidUI控件特效,可以显示水位上升下降效果的TextView
实现android系统前后台的数据封装以及交替
Android开发教程_010_TextView的setText方法 标清
自定义控件_滚动的TextView,跑马灯效果 blog:http://blog.csdn.net/ss1168805219/article/details/51201965
最近开发需要,cell随着textview的高度变化
android中TextView中如何设置水平滚动效果
Android 即时添加textview、imageview内容项,适时动态添加这两个组件,实现时首先创建了所有资源图片(andy、bill、edgar、torvalds、turing)id的数组和所有资源字符串(andy、bill、edgar、torvalds、turing)id...
在对中TextView setText 覆值int 时报错,网上查下原因是setText整型表明是设值R.id.xxx,当然找不到。 解决方法是将int转化为string,用String.valueOf(xxx) 一、我的代码如下:就是我textView设置值 if (list !...
scan_timer_select = (scan_timer_select + 1) % 4; } }; private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan...
首先,在res下面新建一个文件夹drawable,在drawable下面新建三个xml文件:shape_corner_down.xml、shape_corner_up.xml和shape_corner.xml,分别是下面两个角是圆角边框,上面两个角是圆角边框,四个角全部是圆角...
CXTextView 例子 要运行示例项目,请克隆存储库,然后... _textView. initiLine = 2 ; _textView. maxLine = 4 ; _textView. v_margin = 10 ; _textView. h_margin = 15 ; _textView. maxLength = 500 ; _textVi
android:layout_weight="1"> </android.support.v4.view.ViewPager> <TextView android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#737373" /> <TextView ...
text_show=(TextView)findViewById(R.id.text_show); edit_0=(EditText)findViewById(R.id.edit_0); Button button_send=(Button)findViewById(R.id.button_send); button_send.setOnClickListener(this); ...
源码参考,欢迎下载
TextView text = (TextView) layout_tv.getChildAt(i); text.setBackgroundColor(getResources().getColor(R.color.transparent)); RadioButton radioButton = (RadioButton) rg_main.getChildAt(i); if ...