1、AutoCompleteTextView:相对于普通的TextView,AutoCompleteTextView的特点是可以自动提示文本,它可以通过SetAdapter()方法加载适配器。
2、Spinner:一种下拉列表。
布局文件
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/auto_complete_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#2af"/>
</RelativeLayout>
java部分
public class MainActivity extends Activity {
private AutoCompleteTextView mCompleteTextView;
private ArrayAdapter<String> mArrayAdapter;
private String[] mData = {"layout_linear","layout_relative","layout_absolute","text_view","button_image","button_radio"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.spinner_layout);
mCompleteTextView = (AutoCompleteTextView)findViewById(R.id.auto_complete_textview);
mArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.test_list_item,mData);
mCompleteTextView.setAdapter(mArrayAdapter);
}
}
结果演示:
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
java部分
public class MainActivity extends Activity {
private Spinner mSpinner;
private String[] mData = {"layout_linear","layout_relative","layout_absolute","text_view","button_image","button_radio"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSpinner = (Spinner)findViewById(R.id.spinner);
mSpinner.setAdapter(mArrayAdapter);
}
}
结果演示
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android常用控件之AutoCompleteTextView、Spinner
原文地址:http://blog.csdn.net/nizhuanxingheit/article/details/48008755