Simple dial for getting started with Android

Source: Internet
Author: User

:

package jk.phone;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity {protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button = (Button)this.findViewById(R.id.callButton);button.setOnClickListener(new ButtonOnClickListener());}private final class ButtonOnClickListener implements OnClickListener{@Overridepublic void onClick(View v) {      EditText mobileText =(EditText)findViewById(R.id.mobileText);      String mobileNumber = mobileText.getText().toString();      Intent intent = new Intent();      intent.setAction("android.intent.action.CALL");      intent.setData(Uri.parse("tel:"+mobileNumber));      startActivity(intent);}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

Activity_main.xml

<LinearLayout 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"    android:orientation="vertical"    tools:context=".MainActivity" >    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"         android:text="@string/mobileText" />    <EditText        android:id="@+id/mobileText"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:ems="10"       >    </EditText>    <Button        android:id="@+id/callButton"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/callButton" /></LinearLayout>

Strings. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "app_name"> phone </string> <string name = "action_settings"> Settings </string> <string name = "callbutton"> dialing </ string> <string name = "mobiletext"> enter the number to call </string> </resources>

Androidmanifest. xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="jk.phone"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.CALL_PHONE"/>    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="jk.phone.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>            </application></manifest>

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.