2

如何从 autocompletetextview 适配器中选择一个项目并将其设置为默认项目;说我有一个国家列表,我需要在自动完成加载时将法国设置为默认值?

4

2 回答 2

1

您可以简单地使用 autocompleteTextview 的 setText 方法

 String[] country={"France ","USA","Bangladesh","Canada","Other"};
 autocompleteTextView.setText(country[0]);

您可以轻松使用 setText,它非常完美,适合我。

于 2015-11-17T09:32:55.350 回答
-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);
        }
    }
于 2014-03-27T18:52:28.267 回答