如何从autocompletetextview适配器中选择项目并将其设置为默认项目; 说我有一个国家列表,我需要将法国设置为自动完成加载的默认值?
答案 0 :(得分:1)
您可以简单地使用autocompleteTextview的setText方法
String[] country={"France ","USA","Bangladesh","Canada","Other"};
autocompleteTextView.setText(country[0]);
你可以轻松使用setText,它非常适合我。
答案 1 :(得分:-1)
试试这段代码......
###XML:
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="France"
>
<requestFocus />
</AutoCompleteTextView>
###MainActivity:
public class MainActivity extends Activity {
AutoCompleteTextView act;
String[] country={"France ","USA","Bangladesh","Canada","Other"};
ArrayAdapter<String> adapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
act=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
adapter=new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_spinner_item, country);
act.setAdapter(adapter);
act.setThreshold(1);
}
}