我正在实施自动填充功能,目标是选择一个单词时,我不必单击该按钮,它会自动继续,以下是我的代码
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.editText1);
textView.setAdapter(adapter);
textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int pos,
long id) {
Logger.getLogger("test").info("selected");
postData(this);
}
});
日志信息是正确的,postData(View view)
是按钮的onclick功能,但有错误:The method postData(View) in the type MainActivity is not applicable for the arguments (new AdapterView.OnItemClickListener(){})
。那么如何在setOnItemClickListener中调用函数?
答案 0 :(得分:0)
将代码更改为,
textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int pos,
long id) {
Logger.getLogger("test").info("selected");
postData(arg1);
}
});