我在自动完成文本视图时遇到问题,当我输入下拉列表时,我输入时没有显示建议。
我用过的东西:
我使用了API 2.3,当我输入应用程序时,我输入了建议下拉
package com.busticketing.stallionexpress;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AutoCompletetab_1 extends AppCompatActivity {
//auto complete text view
AutoCompleteTextView autoCompleteTextView;
String[] city = {"Nairobi", "Mombasa", "Lamu", "Malindi"};
//** end of auto complete text view
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,city);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,city);
AutoCompleteTextView acTextView = (AutoCompleteTextView)findViewById(R.id.Android);
autoCompleteTextView.setThreshold(3);
autoCompleteTextView.setAdapter(adapter);
}
}
答案 0 :(得分:0)
acTextView
的变量并将adapter
设置为autoCompleteTextView
,这似乎未定义为上面给出的代码。 AutoCompleteTextView
。您更正后的代码
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,city);
AutoCompleteTextView acTextView = (AutoCompleteTextView)findViewById(R.id.Android);
acTextView.setThreshold(3);
acTextView.setAdapter(adapter);