调用 performClick() 函数时一无所获 - Android

我是 Android 开发新手,现在我正在尝试模拟单击我的AutoCompleteTextView对象。我期待默认的 android 键盘外观,可以在元素上输入一些东西


这是一个简单的功能,我正在尝试执行它:


private void someTestMethodName() {

    AutoCompleteTextView tagSearchInput = findViewById(R.id.autoCompleteTextView);

    tagSearchInput.performClick();

}

这是 .xml 元素定义:


<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"/>


摇曳的蔷薇
浏览 123回答 2
2回答

HUWWW

调用performClickaTextView不会弹出软键盘,但您可以自己轻松完成:private void someTestMethodName() {&nbsp; &nbsp; AutoCompleteTextView tagSearchInput = findViewById(R.id.autoCompleteTextView);&nbsp; &nbsp; showSoftKeyboard(tagSearchInput);}public void showSoftKeyboard(View view){&nbsp; &nbsp; if(view.requestFocus()){&nbsp; &nbsp; &nbsp; &nbsp; InputMethodManager imm =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);&nbsp; &nbsp; &nbsp; &nbsp; imm.showSoftInput(view,InputMethodManager.SHOW_IMPLICIT);&nbsp; &nbsp; }}更多信息可以在这里找到:https ://github.com/codepath/android_guides/wiki/Working-with-the-Soft-Keyboard

慕尼黑8549860

我从未使用过 performClick,你不能使用 setOnClickListener 来捕捉点击tagSearchInput.setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View v) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //do somthing&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java