gpt4 book ai didi

java - AutoCompleteTextView onItemSelectedListener 不起作用

转载 作者:IT老高 更新时间:2023-10-28 21:02:05 28 4
gpt4 key购买 nike

我有一个 AutoCompleteTextView 并将 onItemSelectedListener 设置为它,这不起作用。

你知道是什么问题吗?这是我的Activity,如果需要我也可以提供main.xml文件。

   package com.chidem;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class ChidemActivity extends Activity implements OnItemSelectedListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String hop[]=new String[]{
"Karen","Mika","Gevor"
};

AutoCompleteTextView searchHotels = (AutoCompleteTextView) findViewById(R.id.autoSearch);
searchHotels.setOnItemSelectedListener(this);

ArrayAdapter<String> adapter1 = new ArrayAdapter<String>( this, R.layout.list_item, hop);
searchHotels.setAdapter(adapter1);

}


public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.d("autocomplete", "itemselected");

}

public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
}

最佳答案

伙计,你会 mock 你的错误。它为我工作。您添加了 OnItemSelectedListener 而不是 OnItemClickListener

只有在您选择项目或使用轨迹球或上/下箭头浏览 View 时,您的方法才有效。在您的字符串中使用一个以“k”开头的值,比如 Karen1。键入“k”并在 Karen 和 Karen1 之间进行选择。您将看到它有效。如果要单击,则添加 OnItemClickListener 并覆盖

public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3)

关于java - AutoCompleteTextView onItemSelectedListener 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249919/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com