简体   繁体   English

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

[英]Getting nothing while calling performClick() function - Android

I'm new to Android developing and now I'm trying to simulate click on my AutoCompleteTextView object.我是 Android 开发新手,现在我正在尝试模拟点击我的AutoCompleteTextView对象。 I'm expecting default android's keyboard appearance with the possibility to type something at the element我期待默认的 android 键盘外观,可以在元素上输入一些东西

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:这是 .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"/>

Calling performClick on a TextView does not pop up the soft keyboard, but you can quite easily do that yourself:TextView上调用performClick不会弹出软键盘,但您可以很容易地自己做到这一点:

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更多信息可以在这里找到: https : //github.com/codepath/android_guides/wiki/Working-with-the-Soft-Keyboard

i never used performClick, you cant use setOnClickListener to catch a click我从来没有用过 performClick,你不能用 setOnClickListener 来捕捉点击

tagSearchInput.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //do somthing
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM