AutoCompleteTextView开发一个arraylist并选择名称

问题描述 投票:0回答:1

在我的应用程序中,我不会使用AutoCompleteTextView来完成数组列表中的单词。

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_initial_cost );

    String[] tipsNameCost=getResources().getStringArray( R.array.name_costs );

    editTextCostName=(AutoCompleteTextView) findViewById( R.id.edit_text_initial_cost_name );

    ArrayAdapter<String> editTextAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,tipsNameCost);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit_text_initial_cost_name);
    textView.setThreshold(0);
    textView.setAdapter(editTextAdapter);

XML

 <AutoCompleteTextView
        android:id="@+id/edit_text_initial_cost_name"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
        android:layout_weight="1"
        android:editable="true"
        android:inputType="text"
        android:ems="10">

        <requestFocus/>
    </AutoCompleteTextView>

当我点击editTextCostName时我会写这个单词的第一个字母。但我不会这样做当用户点击editextCostName字段时,必须立即显示带有提示供选择的列表。这样他就可以从列表中选择一个单词。怎么做?

java android list listview autocompletetextview
1个回答
0
投票

解:

您可以像这样简单地使用showDropDown()

textView.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(final View arg0) {
        textView.setMaxLines(5);
        textView.showDropDown();

    }
});

就是这样,希望它有效。

© www.soinside.com 2019 - 2024. All rights reserved.