View (views)--autocompletetextview, Spinner

Source: Internet
Author: User

Autocompletetextview

I. Automatic prompt text input box and case-insensitive

Two. Adapter Arrayadapter

1. Data source is string[] or collection, save the text you want to prompt

2.layout file

Three. Completionthreshold

1. Set the minimum number of characters required to prompt

2. Default is 2

1<?xml version= "1.0" encoding= "Utf-8"?>2<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Xmlns:tools= "Http://schemas.android.com/tools"4Android:layout_width= "Match_parent"5android:layout_height= "Match_parent"6android:paddingbottom= "@dimen/activity_vertical_margin"7android:paddingleft= "@dimen/activity_horizontal_margin"8android:paddingright= "@dimen/activity_horizontal_margin"9android:paddingtop= "@dimen/activity_vertical_margin"Tentools:context= "Com.hanqi.testapp2.TestActivity11" Oneandroid:orientation= "Vertical" > A  -<Autocompletetextview -Android:layout_width= "Match_parent" theandroid:layout_height= "Wrap_content" -Android:hint= "Please enter ..." -Android:id= "@+id/at_1" -android:completionthreshold= "1"/> +</LinearLayout>
. XML
1  Packagecom.hanqi.testapp2;2 3 Importandroid.app.Notification;4 ImportAndroid.app.NotificationManager;5 Importandroid.app.PendingIntent;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 Importandroid.support.v7.app.AppCompatActivity;9 ImportAndroid.view.View;Ten ImportAndroid.widget.AdapterView; One ImportAndroid.widget.ArrayAdapter; A ImportAndroid.widget.AutoCompleteTextView; - ImportAndroid.widget.Spinner; - ImportAndroid.widget.Toast; the  -  Public classTestActivity11extendsappcompatactivity { -  - Autocompletetextview at_1; + @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_test11); at  -at_1=(Autocompletetextview) Findviewbyid (r.id.at_1); - //preparing the data source -string[]strings={"abc", "and", "Bea", "Car", "ABCDE", "aaaaaa", "anddd"}; -  -         //preparing the adapter inArrayadapter<string> aa=NewArrayadapter<string> ( This, r.layout.array_adapter,strings); -  to         //building an adapter for a component + at_1.setadapter (AA); -  } the}
. Java

Spinner

I. Concept: drop-down list box

Two. Adapter Arrayadapter

1. Data source is string[] or collection, save the text you want to prompt

2.layout file

Three. Listener Adapterview.onitemselectedlistener ()

1.void onitemselected (adapterview<?> parent, view view, int position, long ID)

2.void onnothingselected (adapterview<?> parent)

1<?xml version= "1.0" encoding= "Utf-8"?>2<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Xmlns:tools= "Http://schemas.android.com/tools"4Android:layout_width= "Match_parent"5android:layout_height= "Match_parent"6android:paddingbottom= "@dimen/activity_vertical_margin"7android:paddingleft= "@dimen/activity_horizontal_margin"8android:paddingright= "@dimen/activity_horizontal_margin"9android:paddingtop= "@dimen/activity_vertical_margin"Tentools:context= "Com.hanqi.testapp2.TestActivity11" Oneandroid:orientation= "Vertical" > A<LinearLayout -Android:layout_width= "Match_parent" -android:layout_height= "Wrap_content" > the<TextView -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" -Android:text= "Education:"/> +<Spinner -Android:layout_width= "0DP" +android:layout_weight= "1" Aandroid:layout_height= "Wrap_content" atAndroid:id= "@+id/sp_1" ></Spinner> -</LinearLayout> -</LinearLayout>
. XML
1  Packagecom.hanqi.testapp2;2 3 Importandroid.app.Notification;4 ImportAndroid.app.NotificationManager;5 Importandroid.app.PendingIntent;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 Importandroid.support.v7.app.AppCompatActivity;9 ImportAndroid.view.View;Ten ImportAndroid.widget.AdapterView; One ImportAndroid.widget.ArrayAdapter; A ImportAndroid.widget.AutoCompleteTextView; - ImportAndroid.widget.Spinner; - ImportAndroid.widget.Toast; the  -  Public classTestActivity11extendsappcompatactivity { -  - Spinner sp_1; + @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_test11); at  -sp_1=(Spinner) Findviewbyid (r.id.sp_1); - //Drop- down list -         FinalString[] xl={"High School", "specialty", "undergraduate", "Master", "PhD"}; -  -Arrayadapter<string> sp=NewArrayadapter<string> ( This, R.LAYOUT.ARRAY_ADAPTER,XL); in  - Sp_1.setadapter (SP); to  +         //Monitor -Sp_1.setonitemselectedlistener (NewAdapterview.onitemselectedlistener () { the @Override *              Public voidOnitemselected (adapterview<?> Parent, view view,intPositionLongID) { $ Panax NotoginsengToast.maketext (TestActivity11. This, "Selected item is" +Xl[position], toast.length_short). Show (); -             } the  + @Override A              Public voidOnnothingselected (adapterview<?>parent) { the  +Toast.maketext (TestActivity11. This, "No choice", Toast.length_short). Show (); -  $             } $         }); -  -     } the}
. Java

View (views)--autocompletetextview, Spinner

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.