android - How to pass a keyEvent object to a Button to let it appears like clicked? -


I have created a surfaceview to accept an OnTouchEvent, and in this view, I manually type with Button.draw Draw a button from (canvas) (do not create a ViewGroup).

Now, this button can be dragged on my SurfaceView, but when I click the button with a broken event button, then the button. TonTouchEvent (keyEvent), but this button can not show the effect

The question is how can I manually pass a main sequence for a scene and it shows that it is a What is shown in the layout ????

Any thoughts? Thx !!

I'm sure there is a better way to do this ... but I could not understand it. So here with what I came up with.

I created my own extension of code, create components of my xmls inside button and MyButton .

  & lt; Com.stackoverflow.android.example.MyButton android: text = "@ + ID / Button 101" Android: ID = "@ + ID / Button 101" Android: layout_width = "wrap-content" Android: layout_height = "wrap-content "& Gt; & Lt; /com.stackoverflow.android.example.MyButton>  

You will need to change each example of button com.stackoverflow.android.example.MyButton .

  package com.stackoverflow.android.example; Import android.content.Context; Import Android.os.Handler; Import android.util.AttributeSet; Import android.util.log; Import android.view.MotionEvent; Import android.view.ViewConfiguration; Import android.widget.Button; Expands the public class mybutton button {Last full MSG_MYBUTTON_HIGHLIGHT_ON = 0; Last full MSG_MYBUTTON_HIGHLIGHT_OFF = 1; Public MyButton (Reference Reference, AttributeSet attrs) {super (references, attrs); } Handler mHandler = new handler () {public Zero handlememes (android.os.Message msg) {switch (msg.what) {case MSG_MYBUTTON_HIGHLIGHT_ON: set pressed (true); SendMessage Header (MSG_MYBUTTON_HIGHLIGHT_OFF, see adjustmentGetSdatDetirection ()); break; Case MSG_MYBUTTON_HIGHLIGHT_OFF: set pressed (wrong); Default: Break; }}; }; Public Zero Display VirtualClick () {mHandler.sendEmptyMessage (MSG_MYBUTTON_HIGHLIGHT_ON); PerformClick (); }}  

Call performVirtualClick function ... which will do.


Comments