Android Basics (3): Phone Dialer

Source: Internet
Author: User

Phone Dialer:

Permissions: Android.permission.CALL_PHONE

Layout code:

< 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"

Tools:context=". Mainactivity ">

< EditText

android:id="@+id/et_number"

android:layout_width="Match_parent"

android:layout_height="Wrap_content"

android:layout_alignparenttop="true"

android:ems="Ten"

Android:inputtype="Phone">

< Requestfocus />

</ EditText >

< Button

android:id="@+id/bt_dail"

android:layout_width="Wrap_content"

android:layout_height="Wrap_content"

android:layout_alignparentright="true"

Android:layout_below="@id/et_number"

Android:text="@string/dail"/>

</ Relativelayout >

Program code:

Package com.example.dail;

import Android.net.Uri;

import Android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.text.TextUtils;

import Android.view.View;

import Android.view.View.OnClickListener;

import Android.widget.Button;

import Android.widget.EditText;

import android.widget.Toast;

Public class Mainactivity extends Activity {

@Override

protected void onCreate (Bundle savedinstancestate) {

Super. OnCreate (savedinstancestate);

// Loading layout Files

Setcontentview (r.layout. Activity_main);

// Find button

Button bt_dail= (button) Findviewbyid (r.id. Bt_dail);

// register a Click event for a button

Bt_dail.setonclicklistener (new MyListener ());

}

Private class MyListener implements Onclicklistener

{

/**

        * how the button is clicked

*/

@Override

Public void OnClick (View arg0) {

EditText et_number= (EditText) Findviewbyid (r.id. Et_number);

String Number=et_number.gettext (). toString ();

// determine if the input is empty

if (Textutils. IsEmpty (number))

{

//toast.length_short This information is displayed for one second

Toast. Maketext (Mainactivity. This," number cannot be empty ", Toast. length_short). Show ();

return;

}

// intention to do something

Intent intent=New Intent ();

// the action of the intended counterpart

Intent.setaction (Intent. Action_call);

// the object that performs the action

Intent.setdata (Uri. Parse("Tel:"+number));

// open a new interface to perform this action

StartActivity (Intent);

}

}

}

Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21

Android Basics (3): Phone Dialer

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.