I am using Accessibility service and want to setText to a special EditText.
First, I get all events in a page recursively:
if(event.getClassName().equals(EditText.class.getName())){
//event.getClassName() gets all events on a screen recursively,
//and if it was an EditText, I want these happen:
if(event.getSource().getText().equals("Hello")){ //special text
event.getSource().setText("Bla Bla Bla"); //change the text
}
}
This seems OK, but I got IllegalStateException
exception, and according to this, I thought that I have to create a new Object of the current event.getClass()
object. I did this:
event.getClass() editText = new event.getClass();
if(editText.getText().equals("Hello")){ //a special text
editText.setText("Bla Bla Bla");
}
Fine, I know it's absolutely wrong, but I mean something exactly like that. Then I tried this:
EditText editText = (EditText) event.getClassName();
Again, seems OK, but I got this:
java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.EditText
How can I get event's class and create on object of? I mean is there anyway to create a new EditText object of current event
object? (In first if
block, I'm making sure that "this specific event" is an EditText).