Android Developer's practical trivia points-1

Source: Internet
Author: User

1. Remove the Actionbar from the Android screen:

1 this. requestwindowfeature (Window.feature_no_title); // Remove title bar 2 // This is a full-screen display of the code            
3 This.getwindow (). SetFlags (Windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_ fullscreen); 3 Setcontentview (r.layout.login);

2. Disable Activity Auto Traverse: Config in re-manifest file

1 <  2     android:name= "Unitestactivity"3    android: Screenorientation= "Landscape">4</activity >

The TextView in 3.Android shows a lot of things he can't drag.

1 <ScrollView>2 <TextView3 Android:id= "@+id/text"4 Android:layout_width= "Wrap_content"5 Android:layout_height= "Wrap_content"6 Android:text= "TextView" />7 </ScrollView>

TextView a lot of content, Scroolview wrapped TextView can be dragged

The difference between 4.int and integer:

int is the basic data type integer is the wrapper class, and the default value for int is 0,integer null. Look at the need to use them

5.Spinner: (Click events and add data to Spinner)

Define an array string[] arr;

Set Arrayadapter adapter=new arrayadapter ();

First say Click event:

1 Spinner.setonitemselectlisonner () {2     toast. (This, arr[arg2]+ "was clicked", Toast. ) Long). Show (); 3 4 }

Add data to the spinner inside:
First, you define a list collection:

1 Private List<string> list;

Add all the data in Arr to the list collection:

 for (int =0;i<arr.length;i++) {Ist.add (arr)};

The button will not be added until it is clicked:

Bt.setonclicklinner (new onclicklintenner) {String str=edit.gettext (). toString (); Adapter.add (str);}}

To delete data from spinner:

Bt.setonclicklistener (new Onclicklistener) {adapter.remove (spinner.getitemselectItem.toString ());}

6. Get the size of the phone screen: The main thing is to use displaymetrics this tool;

1 displaymetrics dis =new displaymetrics ();                         // declare this class 2 Getwindowmanger (). Getdefaultdisplay (). getmetrics (dis);     // to get this kind of service accordingly 3 String str= "screen resolution is" +dis.widthpixes+dis.getheight ();  // methods for calling the DIS class directly

Simplecursoeadapter in 7.Android:

1 cursor c=db. Query (); 2 3 simplecursoradapter adapter=new simplecursoradapter (This, Android.r.layout.simplelist.item_1,c,new sting["name"],new  inte[android.r.id.text1]); 4 5 Adapter.setdropdownview (android.r.layout.pinner1); 6 7 Spinnner.setadpter (adapter);

8.Sqlite Query Detailed:

Db. query{"table name", "new string[]{" to query the column name "}", "condition",new string[]{"Convert the query condition to New string[]{string.valueof ()}"}, null. null. null};

9.Android automatically converts Web pages to clickable: Add an attribute to TextView autolink=all just fine.

10.Android Click two times to exit the program: first set a global variable Boolean exit=false; Click Back to execute a method doexit ();

1  Public BooleanOnKeyDown (keycode,keyevent) {2     if(Code = =keyevent.codeback) {3 doexit ();4     }5 }6 Private voidDoexit () {7     if(!exit) {8Toast.maketoast (Maiin. This, "quit the program at one click", Toast.Long). Show ();9Handler.sendemptymessage (1,2000);Ten}Else { OneMain. This. Finish (); A     } - } -Handler handlre=NewHandler () { the Priva Ovid Handlermessage (Messager msg) { -         Switch(msg.what) { -          Case1: -exit=false; +              Break; -         } +     } A}

11.Android determine whether to connect:

1 connvicimanger con=(Connvitimanger) Getsystem. Server (Context.conntivimanger); 2 Boolena b=con.getactiviinfo (). Isacvle (); // If the returned true is a networked

Custom dialog in 12.Android:

First define the layout of the dialog you want, have a edittext or something, write directly to layout.

Then declare the layout in the activity:

1Linaerlayout layout= (linearlayout) Layoutinflater.from ( This). Infalter (R.layout.dialog,NULL);2 3Edittext edit= (Edittext) Findviewbyid (R.id.edit);//find the EditText in the layout4 5Alertdialog.builder dialog=NewAlertdialog.builder ( This);6 7Dialog.settitle ("Ip setting");8 9 Dialog.seticon (R.drawable.icon);Ten Dialog.setview (Layout) One dialog.setmessage ..... A  -Dialog.setpronegetbutton ("",Newdialoginterface.onclicklinter) { -}

TimerTask in 13.Android: Implements the function to countdown 10 seconds and then execute a method

Define a button, a TextView and a timer:

1Button.setonclicklinster (Newonclicklinster) {2     inti=10;3TimerTask timertask=NewTimerTask () {4      Public voidrun () {5Message msg=NewMessage ();6msg.what=i--;7 handler.sendmessage (msg);8         }9     }TenTimer.hueune (timertask,1000,1000); One } A  -Handler handler=Newhanler{ -      PublicHandler message () { the         if(msg.what>0){ - Text.setext (msg.what); -}Else { -Text.settext ("End"); + Timer,.clean (); -         } +     } A}

Timers in 14.Android:

Declare a chronometer in the layout file

Instantiate in activity and use Chronometer.setbase (systemtime.realtime); This is the start time.

Chronometer.start (); Start timer

Async in 15.Android:

Inherit asynctask this class and replicate three of the methods inside him:

OnPreExecute (): The first method of execution;

Doinbackgroup (): Time-consuming operation performed;

OnPostExecute (): Prompt the user after executing the time-consuming operation;

Android Developer's practical trivia points-1

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.