首页 > 代码库 > Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框
Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框
Activity:
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context="com.example.top5_2.MainActivity" > 7 8 <EditText 9 android:layout_width="fill_parent" 10 android:layout_height="wrap_content" 11 android:paddingLeft="5dp" 12 android:background="#FFA500" 13 android:textSize="16sp" 14 android:drawableLeft="@drawable/ic_launcher" 15 android:text="多匹配自动补全演示" /> 16 <MultiAutoCompleteTextView 17 android:id="@+id/ed" 18 android:layout_width="fill_parent" 19 android:layout_height="wrap_content" 20 style="@android:attr/textViewStyle" 21 android:hint="请输入单词" 22 android:layout_marginTop="10dp" 23 android:completionThreshold="2" 24 /> 25 </LinearLayout>
JAVA:
1 public class MainActivity extends Activity { 2 private MultiAutoCompleteTextView mct; 3 private static final String[] words={"abc","acd","ade"}; 4 @Override 5 protected void onCreate(Bundle savedInstanceState) { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.activity_main); 8 9 mct=(MultiAutoCompleteTextView) findViewById(R.id.ed); 10 ArrayAdapter<String> aa=new ArrayAdapter<String>(this, 11 android.R.layout.simple_dropdown_item_1line,words); 12 mct.setAdapter(aa); 13 mct.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 14 } 15 public boolean onCreateOptionsMenu(Menu menu){ 16 getMenuInflater().inflate(R.menu.main, menu); 17 return true; 18 }
运行效果:
Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。