Som*_*guy 10 android accessibility autocompletetextview
我有一个简单的应用程序,只包含一个AutoCompleteTextView(下面的代码).我有OnItemClickListener和OnItemSelectedListener定义.单击下拉建议中的各个项目会触发该onItemClick事件.但是,使用蓝牙键盘时,使用箭头键导航到给定项目似乎不会触发onItemSelected事件(此事件不会显示日志).
什么触发了这个onItemSelected事件?我的印象是highlight,其中一个下拉项目就是这样,但情况似乎并非如此.
如果OnItemSelectedListener不是突出显示项目的正确事件侦听器,是否满足此要求?
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
public class MainActivity extends Activity {
String[] options = {"a1", "a2", "a3", "b1", "b2", "b3", "b4", "b5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// An adapter object
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, options);
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setThreshold(1);
// Set the listeners
autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("OnItemClick", "[AutoCompleteTextView] Item clicked");
}
});
autoCompleteTextView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.d("onItemSelected", "[AutoCompleteTextView] Item selected");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.d("onNothingSelected", "[AutoCompleteTextView] Nothing here");
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
550 次 |
| 最近记录: |