第二次单击时显示下拉列表 - 带有下拉列表的AutoCompleteTextView

时间:2017-10-11 07:37:27

标签: android autocompletetextview

我的AutoCompleteTextView只有一个简单的下拉列表Home.activity并且效果很好但现在我的应用程序已经准备好发布了,我想删除一些UI故障,所以这里是一个。<登记/> AutoCompleteTextView上的下拉列表包含8个城市名称,它看起来/效果很好,但在第一次点击AutoCompleteTextview时,键盘会弹出,然后再次点击时,下拉列表会出现。
I想要使用键盘第一次点击这个下拉列表。

这是我的实施代码。

<AutoCompleteTextView
        android:layout_width="200dp"
        android:layout_height="30dp"
        android:hint="@string/select_city"
        android:id="@+id/acT1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/shape1"
        android:textAlignment="center"
        app:layout_constraintVertical_bias="0.25"
        android:dropDownHeight="155dp"
        android:cursorVisible="false"
        android:maxLines="1"/>

final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(
                this, android.R.layout.simple_list_item_1, getResources()
                .getStringArray(R.array.Loc_names));
        textView1 = findViewById(R.id.acT1);
        textView1.setAdapter(arrayAdapter);
        textView1.setThreshold(1);
        textView1.setCursorVisible(false);
        textView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                textView1.showDropDown();
                textView1.setCursorVisible(false);
                hideKeyBoard(view);
                selection = (String) parent.getItemAtPosition(position);
                TastyToast.makeText(getApplicationContext(), selection,
                TastyToast.LENGTH_LONG, TastyToast.SUCCESS);
                imageView.setAlpha(.8f);
            }


        });
        textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View arg0) {
                textView1.showDropDown();
                textView1.setCursorVisible(true);
                //imageView.setAlpha(.8f);
            }
        });

Here's the GIF

2 个答案:

答案 0 :(得分:1)

尝试使用ontouch侦听器

textview1.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub

        if(event.getAction() == MotionEvent.ACTION_UP){
            touching = false;
        }else if(event.getAction() == MotionEvent.ACTION_DOWN){
            touching = true;
            handle event
        }
        return true;
    }

答案 1 :(得分:0)

只需将Focus FALSE和Onclickable TRUE添加到AutoCompleteTextView

即可