Chapter 2 dialog box (1) Example of this chapter main interface, Chapter 6th example

Source: Internet
Author: User

Chapter 2 dialog box (1) Example of this chapter main interface, Chapter 6th example

Category: C #, Android, VS2015;

Created on:

In Android applications, common dialogs include Toast, AlertDialog, ProgressDialog, Time Selection, and date selection. This chapter describes the basic usage of these commonly used dialogs.

There are four examples of the source program in this chapter, all of which are in the same project.

Project name: ch06demos

Project template: Blank App (Android)

1. Run

The main interface is run as follows:

Click the sample items in each row to go to the corresponding Sample Page.

2. Main Interface (Main. axml)

Change Main. axml to the following code:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <ListView        android:minWidth="25px"        android:minHeight="25px"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/listView1" /></LinearLayout>

3. Add the topic to the AndroidManifest. xml file.

Set the topic applied to all pages.

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ch06demos.ch06demos" android:versionCode="1" android:versionName="1.0">  <uses-sdk android:minSdkVersion="16" />  <application android:label="ch06demos"    android:theme="@android:style/Theme.DeviceDefault.Light">  </application></manifest>

4. The active file (MainActivity. cs) corresponding to the main interface)

The MainActivity. cs code is as follows:

using System.Collections.Generic;using Android.App;using Android.Widget;using Android.OS;using ch06demos.SrcActivity;namespace ch06demos{    [Activity(Label = "ch06demos", MainLauncher = true, Icon = "@drawable/icon")]    public class MainActivity : Activity    {        string[] items;        protected override void OnCreate(Bundle bundle)        {            base.OnCreate(bundle);            SetContentView(Resource.Layout.Main);            items = new string[]            {                "Demo01:Toast",                "Demo02:AlertDialog",                "Demo03:ProgressDialog",                "Demo04:DatePicker、TimePicker"            };            ListView listView1 = FindViewById<ListView>(Resource.Id.listView1);            listView1.Adapter = new ArrayAdapter<string>(this,                Android.Resource.Layout.SimpleListItem2, items);            listView1.ItemClick += (s, e) =>            {                int index = e.Position + 1;                switch (index)                {                    case 1:                        StartActivity(typeof(Demo01Toast));                        break;                    case 2:                        StartActivity(typeof(Demo02AlertDialog));                        break;                    case 3:                        StartActivity(typeof(Demo03ProgressDialog));                        break;                    case 4:                        StartActivity(typeof(Demo04DatePickerDialog));                        break;                }            };        }    }}

Related Article

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.