I seem to always have a liking for the controls, such as O (cost _ money) O. Recently I plan to write about the use of basic Android controls, hoping to explore some new things.
In this example, text is input from edittext and displayed synchronously in textview to implement real-time input and output. The key is to use onkeylistener to listen to the keyboard input events of edittext.
The example is relatively simple and can be directly written into the code. Main. xml layout:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/input" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/output" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout>
Main activity program:
Package NBE. sense7.vinci. edittext; 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 edittextdemoactivity extends activity {private edittext; private textview;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); edittext = (edittext) findviewbyid (R. id. input); textview = (textview) findviewbyid (R. id. output); // sets the event edittext when the edittext button is input. setonkeylistener (New edittext. onkeylistener () {@ override public Boolean onkey (view arg0, int arg1, keyevent arg2) {// todo auto-generated method stub textview. settext (edittext. gettext (); Return false ;}});}}
As follows:
The entered URL is not displayed as a clickable link. If you want the URL to be highlighted and available, you can add Android: autolink = "all" to textview, for example:
<TextView android:id="@+id/output" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoLink="all" />
As follows: