Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear Edit Text - adb

How to clear focused Edit text using shell command.

I tried

adb shell input keyevent KEYCODE_CLEAR // Not worked 
adb shell input keyevent KEYCODE_DEL // Delete only one char
adb shell input keyevent KEYCODE_FORWARD_DEL // Not worked

With this I am only able to delete upto One character only, Is there any way I can delete/clear the focused Edit text.

like image 668
Krishnakant Avatar asked Sep 07 '15 07:09

Krishnakant


People also ask

How to clear edittext in Android on button click programmatically?

This will be possible using getText ().clear () method. This method will first get the already typed text from edittext and then clear it. So here is the complete step by step tutorial for Clear EditText in android on button click programmatically.

How do I clear ADB logs on Android?

Learn more about bidirectional Unicode characters adb shell // Open or run commands in a terminal on the host Android device. adb logcat -c // clear // The parameter -c will clear the current logs on the device. adb logcat -d > [path_to_file] // Save the logcat output to a file on the local system.

How to remove/delete already typed text inside edittext using edittext?

How to remove/delete already typed text inside edittext to empty edittext on button click dynamically. In this tutorial we are programmatically removing the typed text from EditText so application user doesn’t need to remove text by hand back press keypad key. This will be possible using getText ().clear () method.

How to remove edittext underline programmatically in Android?

Click here to download Clear EditText in android on button click programmatically project with source code. Related Posts. Move EditText layout just above soft keyboard when it shows in android. Open new activity on button click in android by existing activity. Remove EditText underline programmatically in android.


2 Answers

This works for me:

function clear_input() {
    adb shell input keyevent KEYCODE_MOVE_END
    adb shell input keyevent --longpress $(printf 'KEYCODE_DEL %.0s' {1..250})
}

Then:

clear_input
like image 153
Pedro Rodrigues Avatar answered Oct 17 '22 14:10

Pedro Rodrigues


The only way that I have found so far is to get the proper coordinates to use input swipe x y x y duration to simulate a long press. This will then highlight all the text in the EditText field. You can then send the keys you want to replace what was there.

I just wish that adb shell input keyevent KEYCODE_CLEAR would clear all the text in the field. That would make things so much easier, if someone can find a better way that would be great.

like image 35
aziannomness Avatar answered Oct 17 '22 14:10

aziannomness