当我填写姓名并选择自动完成文本视图时。它不是同一个微调器。功能在if-else不工作或条件不正确(我不知道)。请建议我如何在自动完成文本视图上使用onitemselectlistener在每种情况下使用函数。
AutoCompleteTextView auto1 = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
String[] word;
word = getResources().getStringArray(R.array.word_name);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, word);
auto1.setAdapter(adapter);
auto1.setOnItemSelectedListener(new OnItemSelectedListener() {
TextView txt1 = (TextView)findViewById(R.id.textView1);
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
if(arg2==0) // when I fill AED(array 0 in string.xml It's not work)
{
getmoney();
}
else if(arg2==1)
{
getmoney1();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
String.xml
<string-array name="word_name">
<item>AED United Arab Emirates Dirham</item>
<item>AFN Afghan Afghani</item>
<item>ALL Albanian Lek</item>
<item>AMD Armenian Dram</item>
</string-array>
答案 0 :(得分:1)
而不是OnItemSelectedListener
,OnItemClickListener
适用于AutocompleteTextView
。
例如:
auto1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this,
adapter.getItem(position).toString(),
Toast.LENGTH_SHORT).show();
}
});