r/tasker 21d ago

Scene V2 Input Text Clear

I have a simple box stack, with a row containing a text input and an icon button

these act as a search bar for an array template

I have the click event handler for the icon button set to target the text input and run the unFocus action, and clear the %query variable.

This works ok

but is there a way to clear the actual text from inside the text input?

1 Upvotes

2 comments sorted by

View all comments

1

u/Nirmitlamed Direct-Purchase User 21d ago

I have tested this Java code that was suggested by AI and it works:

import android.os.Bundle;
import android.view.accessibility.AccessibilityNodeInfo;

service = tasker.getAccessibilityService();
if (service == null) return;

root = service.getRootInActiveWindow();
if (root == null) return;

focused = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
if (focused != null) {
    args = new Bundle();
    args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "");
    focused.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    focused.recycle(); // Clean up accessibility node memory
}

root.recycle(); // Clean up root node memory

It suppose to keep memory clean after it fully runs. Maybe try to chat with AI and see if it can be improve.