How to set selection of editText by using SendKeyEvent function of InputConnection class

by DrBrain » Thu, 30 Apr 2009 02:06:02 GMT


Sponsored Links
 I need to set selection of an editText box via InputConnection. I used
the SendKeyEvent function with the KEYCODE_DPAD_LEFT and META_SHIFT_ON
state but I've had no luck. My code is as below:

...
// I've already received hardware key event of DPAD left key as event
parameter in this function.

// Change the meta state of event parameter to META_SHIFT_ON
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
                        event.getAction(), event.getKeyCode(), 
event.getRepeatCount(),
KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE|
KeyEvent.META_SHIFT_LEFT_ON|KeyEvent.META_SHIFT_ON,
                        event.getDeviceId(), event.getScanCode());
InputConnection ic = getCurrentInputConnection();
ic.sendKeyEvent(event);

After excuting the code, there still no selection in the EditText.

Could somebody help me to resolve this ?

Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Reading sensor values directly at regular intervals rather than using onSensorChanged(SensorEvent evt)

Gentlemen,

Up until now I have been using SensorEventListener.onSensorChanged
(SensorEvent evt) to obtain data values from the on board sensors (G1)
whenever a sensor event occurs (snippet below). However, what I really
want to be able to do is read the values of the sensors at a regular
intervals, at say a frequency of 0.1s rather than reacting to the
triggered event (for DSP purposes). Is there a way of reading the
sensor values directly without having to use/wait for onSensorChanged
() ?

Many thanks in advance.


----------

Snippet - currently using onSensorChanged(SensorEvent evt):

SensorManager sman = (SensorManager) getSystemService
(Context.SENSOR_SERVICE);
                List<Sensor> accelerometer = sman.getSensorList
(Sensor.TYPE_ACCELEROMETER);
                Sensor myAccelerometer = accelelerometer.get(0);

                sman.registerListener(new SensorEventListener() {

                        public void onAccuracyChanged(Sensor arg0, int arg1) {

                        }

                        public void onSensorChanged(SensorEvent evt) {

                                // read new sensor values
                                accelTextView.setText("X-accel: " + 
evt.values[0] + "\n" + "Y-
accel: "
                                                + evt.values[1] + "\n" + 
"Z-accel: " + evt.values[2]);
                                accelTextView.invalidate();


                                // sleep for a bit
                               try {
                                        Thread.sleep(10);
                                } catch (Exception ex) {
                                        accelTextView.setText("Erk!");
                                }
                        }

                }, myAccelerometer, SensorManager.SENSOR_DELAY_UI);

--~--~---------~--~----~------------~-------~--~----~

2. Selling license for free apps

Hi Guys,

Like many other developers here, I can't sell applications from my country
and seeking a way for monetization of my app.

I was thinking to release my app as free ads-supported version, and to sell
license from my website for those who want to remove the ads completely.
Actually users will apply on my website, pay a fee and I will send a
license.

But then I came across the following url saying that "collecting payments
through your application is not allowed under the Android Market Developer
Distribution Agreement":
http://market.android.com/support/bin/answer.py?hl=en&answer=140504

Is this to prohibit me from doing what I explained above?

Thank you,
Armond


--~--~---------~--~----~------------~-------~--~----~

3. How to build EditText view like that in Android Market where "X" button appears for clearing text?

4. Widgets and custom components?

5. Prevent radio button from being checked when being clicked

6. WebView onLoadComplete()?

7. Last modification time for each contact record in People table