Xamarin.android Multi-Interface

Source: Internet
Author: User

First, you must complete the tutorial http://www.cnblogs.com/yaozhenfa/p/xamarin_android_quickstart.html before you begin this tutorial, otherwise you will not be able to continue.

Ii. interface 1. Open the Resources/layout/main.axml file and continue to add a button below the call button and set its ID to @+id/callhistorybutton and set text to @string/ Callhistory (This is actually an identifier for a string resource, which we will add later):

III. Resources 1. Open Resources/values/strings.xml File

2. and add a string resource with name Callhistory:

3. Back to Main.axml you can see that the last button shows a string that has been changed:

4. The previous Call button was disabled by code, and this time we will callhistory the button through the property that changes:

You can see that the button is disabled:

Iv. code 1. Right-click the project and create a new activity named Callhistoryactivity:

2. Open the newly created activity, modify the title name of the activity, inherit the class, and display an array of strings passed in:
1 namespacephoneword_droid2 {3[Activity (Label ="@string/callhistory")]4      Public classcallhistoryactivity:listactivity5     {6         protected Override voidOnCreate (Bundle bundle)7         {8             Base. OnCreate (bundle);9             //get the arguments passed from the intent .Ten             varPhonenumbers = Intent.Extras.GetStringArrayList ("phone_numbers") ??New string[0]; One  A             //displays an array of strings to the list control (because Listactivity is inherited, so the entire view is a list) -              This. ListAdapter =Newarrayadapter<string> ( This, Android.Resource.Layout.SimpleListItem1, phonenumbers); -  the             //the second argument about Arrayadapter is actually a view of each item in the specified list, followed by a customized way to control the list's items -         } -     } -}
View Code

3. Back to MainActivity.cs, since the history is to be displayed, then nature must be able to save so we need to define a variable:
1[Activity (Label ="phoneword_droid", Mainlauncher =true, Icon ="@drawable/icon")]2      Public classmainactivity:activity3     {4         Static ReadOnlylist<string> phonenumbers =Newlist<string> ();
View Code

4. The listener event is then also bound for Callhistorybutton to open another activity (append continues after OnCreate):
1Button Callhistorybutton = findviewbyid<button>(Resource.Id.CallHistoryButton);2Callhistorybutton.click + = (E, t) = =3             {4                 //Specify the activity that the intent needs to open5                 varIntent =NewIntent ( This,typeof(callhistoryactivity));6                 //set parameters for intent passing7Intent. Putstringarraylistextra ("phone_numbers", phonenumbers);8 startactivity (intent);9};
View Code

5. We lack a way to add a history, and here we should put it in the call method of the dialog, so that only the phone that is dialed will enter the history:
1                 //Dial Button2Calldialog.setneutralbutton ("Pager",Delegate3                 {4                     //add a phone to the history list5 Phonenumbers.add (translatednumber);6 7                     //if the definition of Callhistorybutton is going to go wrong after this code, we need to8                     //Button Callhistorybutton = findviewbyid<button> (Resource.Id.CallHistoryButton); code in advance9callhistorybutton.enabled =true;Ten  One                     //use intent to make a phone call A                     varCallintent =NewIntent (intent.actioncall); -  -                     //set the number of calls you want to make to an intent parameter theCallintent.setdata (Android.Net.Uri.Parse ("Tel:"+translatednumber)); -                      - startactivity (callintent); -});
View Code

Five, the operation

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.