I. Autocompletetextview automatic prompt text input box
1. Properties: Case insensitive.
2.ArrayAdapter Adapter
The data source is a string[] or collection that holds the text to be prompted; Layout file.
3.completionThreshold: Set the minimum number of characters required for the hint, default is 2.
Two. Spinner drop-down list
1.ArrayAdapter Adapter
The data source is a string[] or collection that holds the text to be prompted; Layout file.
2. Listener Adapterview.onitemselectedlistener ()
1-void onitemselected (adapterview<?> parent, view view, int position, long ID)
2-void onnothingselected (adapterview<?> parent)
Three. Message prompt
1.Toast
1-maketext (), build and return toast;
1>context
2> message Content
3> Display Duration: toast.length_short short/Toast.length_long long.
2-show () display
2.Notification Status Message Bar (can jump to activity)
1-Get Notificationmanager
1> (Notificationmanager) getsystemservice (Notification_service)
2>notificationmanager is a system built-in service
2-Build Notification
New Notification.builder () builder
1>setcontenttitle Setting the content title
2>setcontenttext Setting Content Text
3>setsmallicon Settings icon
4>setticker Setting the status bar prompt
5>setdefaults set prompt way: Notification.default_sound sound, others need authorization.
6>setautocancel set whether to automatically disappear after clicking the jump: True by default.
7>setcontentintent Setting Content Intent
<1> Create Intent
<2> Generate pendingintent pi = pendingintent.getactivity (context, 0 request code, intent intent, 0 mark);
8>build () creates and returns notification
3-Send message by Notificationmanager
Notify (ID, message);
Code and presentation:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Android:paddingbottom= "@dimen/activity_vertical_margin"7 Android:paddingleft= "@dimen/activity_horizontal_margin"8 Android:paddingright= "@dimen/activity_horizontal_margin"9 Android:paddingtop= "@dimen/activity_vertical_margin"Ten Tools:context= "Com.example.wang.testapp2.TestActivity11" One android:orientation= "vertical"> A - <Autocompletetextview - Android:layout_width= "Match_parent" the Android:layout_height= "Wrap_content" - Android:hint= "Please enter ..." - Android:id= "@+id/at_1" - Android:completionthreshold= "1"/> + - <LinearLayout + Android:layout_width= "Match_parent" A Android:layout_height= "Wrap_content"> at <TextView - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - Android:text= "Education:"/> - - <Spinner in Android:layout_width= "0DP" - Android:layout_weight= "1" to Android:layout_height= "Wrap_content" + Android:id= "@+id/sp_1"></Spinner> - </LinearLayout> the * <Button $ Android:layout_width= "Match_parent"Panax Notoginseng Android:layout_height= "Wrap_content" - Android:text= "Send status bar message" the Android:onclick= "Bt_onclick"/> + </LinearLayout>
. XML
1 Packagecom.example.wang.testapp2;2 3 Importandroid.app.Notification;4 ImportAndroid.app.NotificationManager;5 Importandroid.app.PendingIntent;6 Importandroid.content.Intent;7 Importandroid.support.v7.app.AppCompatActivity;8 ImportAndroid.os.Bundle;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; + - Spinner sp_1; + A @Override at protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_test11); - -at_1=(Autocompletetextview) Findviewbyid (r.id.at_1); -sp_1=(Spinner) Findviewbyid (r.id.sp_1); in - //preparing the data source toString [] strings={"abc", "and", "Bea", "Car", "ABCDE", "aaaaaa", "anddd"}; + - //preparing the adapter theArrayadapter<string> aa=NewArrayadapter<string> ( This, r.layout.array_adapter,strings); * $ //to set an adapter for a componentPanax Notoginseng at_1.setadapter (AA); - the //Drop- down list + FinalString [] xl={"High School", "specialty", "undergraduate", "Master", "PhD"}; A theArrayadapter<string> sp=NewArrayadapter<string> ( This, R.LAYOUT.ARRAY_ADAPTER,XL); + - Sp_1.setadapter (SP); $ $ //Listener -Sp_1.setonitemselectedlistener (NewAdapterview.onitemselectedlistener () { - @Override the Public voidOnitemselected (adapterview<?> Parent, view view,intPositionLongID) { - WuyiToast.maketext (TestActivity11. This, "Selected item is" +Xl[position], toast.length_short). Show (); the } - Wu @Override - Public voidOnnothingselected (adapterview<?>parent) { About $Toast.maketext (TestActivity11. This, "No choice", Toast.length_short). Show (); - } - }); - A + } the - $ //Send Message the Public voidBt_onclick (View v) the { the //1. Get status Bar message manager theNotificationmanager nm=(Notificationmanager) Getsystemservice (notification_service); - in //Prepare Pendingintent the //1) Create intent theIntent intent=NewIntent ( This, TestActivity1.class); About the //2) Generate thePendingintent pi=pendingintent.getactivity ( This, 0, intent, 0); the + //2. Build status bar Messages -Notification nt=NewNotification.builder ( This) the. Setcontenttitle ("Weather Forecast")Bayi. Setcontenttext ("Tomorrow clear, temperature 30 ℃") the . Setsmallicon (R.drawable.tianqi) the. Setticker ("New Weather Forecast") - . SetDefaults (Notification.default_sound) -. Setautocancel (false) the . Setcontentintent (PI) the . Build (); the the - //3. Sending messages by manager theNm.notify (0, NT); the the }94}. Java
View--autocompletetextview, spinner, and message hints