Chapter 1 common basic controls (1) -- Examples of the main interface in this chapter, Chapter 2 Examples

Source: Internet
Author: User

Chapter 1 common basic controls (1) -- Examples of the main interface in this chapter, Chapter 2 Examples

Category: C #, Android, VS2015;

Created on:

This chapter describes the basic usage of simple Android controls. There are nine examples of the source program in this chapter, all of which are in the same project.

Project name: ch05demos, Project template: Blank App (Android)

The main running interface is as follows:

Click the sample items in each row to go to the corresponding Sample Page. 1. Add an image in the drawable folder.

For the added image, see the left image below. You can also drag and drop the image to the drawable folder.

The right figure shows the vertical screen layout file (layout folder), horizontal screen layout file (layout-land folder), and pop-up menu layout file (menu folder) after implementation in each example ). These are added in the section to be introduced later in this chapter.

2. Main Interface (Main. axml)

The modified code is as follows:

<?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. The active file (MainActivity. cs) corresponding to the main interface)

The MainActivity. cs code is as follows:

using System;using Android.App;using Android.Widget;using Android.OS;using ch05demos.SrcActivity;namespace ch05demos{    [Activity(Label = "ch05demos", 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[]            {                "Demo01EditText",                "Demo02Login",                "Demo03MultiResolution",                "Demo04CheckBoxRadioButton",                "Demo05Spinner",                "Demo06SwitchAndRatingBar",                "Demo07PopupMenu",                "Demo08Gallery",                "Demo09SeekBar"            };            ListView listView1 = FindViewById<ListView>(Resource.Id.listView1);            listView1.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);            listView1.ItemClick += (s, e) =>            {                int index = e.Position + 1;                switch(index)                {                    case 1:                        StartActivity(typeof(Demo01EditText));                        break;                    case 2:                        StartActivity(typeof(Demo02Login));                        break;                    case 3:                        StartActivity(typeof(Demo03MultiResolution));                        break;                    case 4:                        StartActivity(typeof(Demo04CheckBoxRadioButton));                        break;                    case 5:                        StartActivity(typeof(Demo05Spinner));                        break;                    case 6:                        StartActivity(typeof(Demo06SwitchAndRatingBar));                        break;                    case 7:                        StartActivity(typeof(Demo07PopupMenu));                        break;                    case 8:                        StartActivity(typeof(Demo08Gallery));                        break;                    case 9:                        StartActivity(typeof(Demo09SeekBar));                        break;                }            };        }    }}

4. list file (AndroidManifest. xml)

Add only one content to this file: Set the public themes applied to all pages.

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

Starting from the next section, we will introduce how to implement various examples and the concepts involved in these examples.

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.