我有一个显示在AutoCompleteTextView中的项目数组,我想加载附加到AutoCompleteTextView中选择的值的html
所以我尝试使用OnItemSelected但没有任何反应
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_horarios);
mytext = findViewById(R.id.displayResult);
actv_grupos = (AutoCompleteTextView)findViewById(R.id.actv_grupos);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.array_grupos, android.R.layout.simple_dropdown_item_1line);
actv_grupos.setAdapter(adapter);
actv_grupos.setOnItemSelectedListener(this);
}
itemSelected函数
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String grupo = (String) parent.getItemAtPosition(position);
if(position != 0) {
abrirUrl(grupo);
}
}
答案 0 :(得分:0)
使用OnItemSelected()
内的setOnItemClickListener()
进行解决,如下所示:
actv_grupos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String grupo = (String) parent.getItemAtPosition(position);
if(position != 0) {
abrirUrl(grupo);
}
});