In Android, text is synchronously displayed in textview after edittext is entered.

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.