`
xsuo
  • 浏览: 123360 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Android Development Demo: “DialANumber”

阅读更多

While I think the Android development examples are not really good and straight forward perhaps some of you come along with them. However, I would like to provide you a very very simple example here on how to write your own first Android program.

This is technically very easy. Once you got Eclipse and Android installed and running on your computer (I use a Mac OS Leopard powered MacBook but you can use a Microsoft Windows XP/Vista/etc. PC as well) you just start Eclipse. Now you just go to “New » Project... » Android » Android Project...” and enter the required data. Once you are done the result might look like this:

Android Development Demo: “DialANumber”

Now you can start writing and customize the default “Hello World” a.k.a. “Hello Android” app which just shows a text field. If you are really really lazy you could also copy/paste the following code:


package com.DialANumber;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class DialANumber extends Activity {
EditText mEditText_number = null;
LinearLayout mLinearLayout_no_button = null;
Button mButton_dial = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mLinearLayout_no_button = new LinearLayout(this);

mEditText_number = new EditText(this);
mEditText_number.setText("5551222");
mLinearLayout_no_button.addView(mEditText_number);

mButton_dial = new Button(this);
mButton_dial.setText("Dial!");
mLinearLayout_no_button.addView(mButton_dial);
mButton_dial.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
performDial();
}
});

setContentView(mLinearLayout_no_button);
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CALL) {
performDial();
return true;
}
return false;
}

public void performDial(){
if(mEditText_number!=null){
try {
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mEditText_number.getText())));
} catch (Exception e) {
e.printStackTrace();
}
}//if
}
}

That was quick!:)

Now you should create a debug runtime configuration which can be done at “Run » Debug Configurations…“. Here you select “Android Application” and press “New“. Enter a name and select the “DialANumber” project. Launching the default Activity might be a good idea as we not know what the f*** it means right now.:)So just hit “Apply” and “Debug” and the program will be started in the Android simulator. To give you a clue how that looks like here are some screen shots:

Android Development Demo: “DialANumber”

Android Development Demo: “DialANumber”

As there is an EditField for the phone number which can be modified you can also enter a new phone number in there. An example of this comes here:

Android Development Demo: “DialANumber”

Android Development Demo: “DialANumber”

As everyone can see we are able to dial the number in two different ways:

  1. Hit the “Dial!” button next to the input field.
  2. Hit the “green dial” button on the bottom of the device.

Here is an illustration of this:

Android Development Demo: “DialANumber” - How to write your own very first Android program - Made Simple!

That’s it. Pretty easy, huh?:)

I am looking forward to find some time in the near future to pimp this example a bit. I am thinking of a number field filter adding (which looks a bit confusing in the API documentation) or something else. Suggestions are welcome!

In case someone isreally lazyinterested you can download the whole example project here:dialanumber.zip.

分享到:
评论

相关推荐

    head first android development: a brain-friendly guide 2nd edition

    head first android development: a brain-friendly guide 2nd edition,英文第二版,清晰无水印,带书签

    Android 入门demo源码

    8. **Android SDK**: 开发Android应用需要Android Software Development Kit,它提供了编译、构建、调试所需的工具和库。 9. **构建过程**: 使用Eclipse时,通过点击“Run”按钮或使用快捷键可以启动应用的编译和...

    Learn Android Studio 3 Efficient Android App Development epub

    Learn Android Studio 3 Efficient Android App Development 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    advanced android development : lecture7

    1. **多线程与异步处理**:Android应用在主线程中执行UI操作,而后台任务应放在其他线程中执行以避免阻塞UI。Lecture 7可能会涵盖AsyncTask、IntentService、Handler/Looper机制,以及现代的协程(Coroutines)和...

    android-demo:Android有用的演示

    标签"C++"表明项目可能利用了Android的Native Development Kit (NDK),允许开发者使用C++编写部分性能敏感的代码,实现更高效的计算或访问硬件功能。这可能涉及到JNI(Java Native Interface)的使用,以及C++与...

    TUTK android端demo

    【TUTK Android端Demo详解】 TUTK(全称可能为“TuTuK”或“涂图克”)是一款面向Android平台的SDK,通常用于实现特定的功能或服务,如视频处理、直播互动、游戏开发等。这个"android端demo"是开发者用来学习和理解...

    Android Developer Website:官方安卓开发网站,提供了开发相关的文档、API 文档和工具 Android

    Android NDK:官方安卓 Native Development Kit,提供了开发安卓应用程序的 Native 代码所需的工具和资源。 Android Documentation:官方安卓开发文档,提供了详细的开发指南和 API 文档。 开源资源 GitHub:一个...

    The Busy Coder's Guide to Android Development 8.1

    The Busy Coder's Guide to Android Development Android开发经典图书, 最新版8.1 epub格式,pdf太大了

    Android JNI demo

    4. 编译本地代码:使用NDK(Native Development Kit)的工具链编译C/C++源代码,生成.so动态链接库。 5. 将.so库添加到Android项目:将生成的.so文件放入项目的`jniLibs`目录下,对应不同架构的文件(armeabi, ...

    Android 6 Programming: Android Studio Development Guide

    This is a guide to Android application developers on how to use Android Studio 6 to develop their apps. The first part is a guide on how to use the Code Editor in Android 6. The Code Editor provides ...

    The Busy Coder's Guide to Android Development: Version 8.2

    The Busy Coder's Guide to Android Development: Version 8.2 Supports Through Android 7.1 2017 | English | ASIN: B06Y4TCV7F | 756 pages | PDF + EPUB (conv) | 63 Mb Do you want current information about...

    Head First Android Development A Brain-Friendly Guide(2nd)

    2. **Android SDK与环境配置**:Android SDK是开发Android应用的基础,包括各种库、工具和API文档。书中会详细讲解如何安装和配置SDK,以及如何设置开发环境。 3. **基本UI组件**:书中会涵盖Android中的用户界面...

    The Busy Coder's Guide to Android Development 8.9 - 2017.mobi

    The Busy Coder's Guide to Android Development 8.9 - 2017.mobi kindle 可以用

    TaurusXAds_Android_Demo:适用于TaurusXAds SDK的Android演示应用

    【TaurusXAds_Android_Demo】是一款专为TaurusXAds SDK设计的Android平台上的演示应用程序,旨在帮助开发者理解和学习如何在Android项目中集成和使用TaurusXAds广告平台。这个SDK可能提供了多种广告格式,如横幅广告...

    AndroidDemo:安卓学习笔记

    【AndroidDemo:安卓学习笔记】 AndroidDemo 是一个典型的Android应用开发项目,主要针对初学者,旨在帮助他们理解和掌握Android开发的基础知识。这个项目的核心是Java编程语言,因为Android应用程序主要用Java编写...

    AndroidDemo:安卓实践

    【AndroidDemo:安卓实践】 AndroidDemo 是一个专为学习和实践安卓应用开发而设计的项目。这个项目集合了各种Android编程实例,旨在帮助开发者提升在Android平台上的编程技能。通过参与这个项目,开发者可以深入了解...

Global site tag (gtag.js) - Google Analytics