Android Learning note 001-making a phone call

Source: Internet
Author: User

Write the Android program for the first time and write a simple dialer: very simple

As follows:

The code for Mainactivity.java is as follows:

 PackageCom.example.dailcall;Importandroid.support.v7.app.ActionBarActivity;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classMainactivityextendsactionbaractivity {//define buildPrivateEditText et; PrivateButton btn; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); ET=(EditText) Findviewbyid (r.id.et_number);//through Findviewbyid to find the build name, bind to the defined build variable. BTN=(Button) Findviewbyid (R.id.btn_dail); Btn.setonclicklistener (NewView.onclicklistener () {//define a Click event response for the button @Override Public voidOnClick (View v) {//TODO auto-generated Method StubIntent intent=NewIntent ();//define a Intent.                Intent.setaction (Intent.action_call); Intent.setdata (Uri.parse ("Tel:" +Et.gettext (). toString (). Trim ()));                            /WHERE Tel: Be sure to add, otherwise error startactivity (intent);    }        }); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml.        intID =Item.getitemid (); if(id = =r.id.action_settings) {            return true; }        return Super. onoptionsitemselected (item); }}

The Activity_main.xml layout file is as follows:

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context= "Com.example.dailcall.MainActivity" > <EditText Android:id= "@+id/et_number"//the ID of the definition must be meaningful, convenient for yourself and others to read and quote.Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:inputtype= "Phone" > <requestfocus/> </EditText> <Button Android:id= "@+id/btn_dail"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@+id/et_number"Android:text= "@string/dail"/></relativelayout>

Android Learning note 001-making a phone call

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.