Getting nothing while calling performClick() function - Android

Andrey Belonog :

I'm new to Android developing and now I'm trying to simulate click on my AutoCompleteTextView object. I'm expecting default android's keyboard appearance with the possibility to type something at the element

Here is a simple function, where I'm trying to perform it:

private void someTestMethodName() {
    AutoCompleteTextView tagSearchInput = findViewById(R.id.autoCompleteTextView);
    tagSearchInput.performClick();
}

And here is .xml element defining:

<AutoCompleteTextView
        android:id="@+id/autoCompleteTextView"
        android:text="TextView"
        android:layout_width="188dp"
        android:layout_height="62dp"
        android:layout_alignParentStart="true"
        android:layout_marginStart="108dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="292dp"/>
Bart Friederichs :

Calling performClick on a TextView does not pop up the soft keyboard, but you can quite easily do that yourself:

private void someTestMethodName() {
    AutoCompleteTextView tagSearchInput = findViewById(R.id.autoCompleteTextView);
    showSoftKeyboard(tagSearchInput);
}

public void showSoftKeyboard(View view){
    if(view.requestFocus()){
        InputMethodManager imm =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view,InputMethodManager.SHOW_IMPLICIT);
    }
}

More information can be found here: https://github.com/codepath/android_guides/wiki/Working-with-the-Soft-Keyboard

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=151879&siteId=1