Android 第二次单击时会显示下拉菜单-AutoCompleteTextView带有下拉菜单
我的Android 第二次单击时会显示下拉菜单-AutoCompleteTextView带有下拉菜单,android,autocompletetextview,Android,Autocompletetextview,我的主页上有一个自动完成文本视图,带有一个简单的下拉菜单。活动,效果很好,但现在我的应用程序即将发布,我想消除一些用户界面故障,这里有一个。 AutoCompleteTextView上的下拉列表包含8个城市名称,它看起来/工作得很好,但首先单击AutoCompleteTextView,键盘会弹出,然后再次单击时,下拉列表就会出现。我希望这个下拉列表在用键盘第一次单击时出现。这是我的实现代码 <AutoCompleteTextView android:layout_width
主页上有一个自动完成文本视图
,带有一个简单的下拉菜单。活动
,效果很好,但现在我的应用程序即将发布,我想消除一些用户界面故障,这里有一个。AutoCompleteTextView
上的下拉列表包含8个城市名称,它看起来/工作得很好,但首先单击AutoCompleteTextView
,键盘会弹出,然后再次单击时,下拉列表就会出现。我希望这个下拉列表在用键盘第一次单击时出现。
这是我的实现代码
<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);
}
});
只需将焦点FALSE和Onclickable TRUE添加到AutoCompleteTextView中即可尝试使用ontouch listener
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;
}
您的下拉列表外观的屏幕截图?@Prakaram。如果您不在双击时打开列表,而将其作为autocompletetextview的一项功能,它将在下拉列表中显示输入查询的筛选结果。请尝试使用要显示下拉列表的数据集的阈值或“performFiltering”属性。否则,当您输入一些字符时,它将显示下拉列表。问题是,它将作为微调器在第一次单击时打开。尝试此操作,它将正常工作