美文网首页
AutoCompleteTextView

AutoCompleteTextView

作者: lucas777 | 来源:发表于2022-04-04 21:39 被阅读0次

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //主代码
        String[] arrs = new String[]{"abc","adaadfa","张三","李四","abc","abc","王麻子","李世民"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,arrs);
        
        AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
        actv.setAdapter(adapter);
    }
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <AutoCompleteTextView
        android:id="@+id/actv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="输入a,张,李 试试"
        android:completionThreshold="1" />

</RelativeLayout>

相关文章

网友评论

      本文标题:AutoCompleteTextView

      本文链接:https://www.haomeiwen.com/subject/ewkhsrtx.html