Implementation of Android analog keyboard input function

Source: Internet
Author: User

When doing the instructions on the input box, it is much better to use the dynamic input effect than the static picture, this article introduces the implementation of the Android platform analog keyboard input with the function of a search input operation guide which needs to be implemented recently.

On Android do not know how to record GIF dynamic diagram, directly look at the effect of it, specifically to see the demo on the line.


The implementation is simple, open a thread, through the sleep control input character interval time, encapsulates a method of simulating keyboard input, the final code is this:

public class Typeinactivity extends baseactivity {@Overridepublic void Setcontentview () {Setcontentview ( R.layout.activity_type_in_layout);} @Overridepublic void Findviews () {} @Overridepublic void GetData () {} @Overridepublic void Showconent () {showguide ();} public void OnClick (View v) {switch (V.getid ()) {case r.id.searchbtnid:{}break;default:{}break;}} private void ShowGuide () {New Thread (new Runnable () {@Overridepublic void run () {try {thread.sleep ();} catch (Inte Rruptedexception E1) {e1.printstacktrace ();} "Rotation" Pinyin int[] Keycodearray = new Int[]{keyevent.keycode_x,keyevent.keycode_u,keyevent.keycode_a,keyevent.keycode_ N,keyevent.keycode_space,keyevent.keycode_z,keyevent.keycode_h,keyevent.keycode_u,keyevent.keycode_a, keyevent.keycode_n};for (int keycode:keycodearray) {try {Typein (keycode); Thread.Sleep (200);} catch (Interruptedexception e) {e.printstacktrace ();}}}}). Start ();} private void Typein (final int keycode) {try {instrumentation inst = new Instrumentation (); inst.Sendkeydownupsync (keycode);} catch (Exception e) {log.e ("Exception when Sendkeydownupsync", e.tostring ());}}}

Baseactivity.java: (The individual has been used to writing this ...) )

Public abstract class Baseactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); init ();} private void Init () {Setcontentview (); Findviews (); GetData (); Showconent ();} public abstract void Setcontentview ();p ublic abstract void Findviews ();p ublic abstract void GetData ();p ublic Abstract V OID showconent ();}
then find a simulation of the typing of sound, in the analog input when playing the pronunciation effect, the effects are still possible ...


Implementation of Android analog keyboard input function

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.