您的位置:首页 > 移动开发 > Android开发

Android学习-HelloWorldAndroid

2010-05-08 14:36 423 查看
这段时间比较的闲,突然想学学一些新的东西,就搭建了一个windows平台下的android开发环境,学学Google android手机应用程序开发。在此,小结一下,android菜鸟学习笔记。

编程环境

操作系统:windows xp sp3

IDE:Eclipse 3.3.2

Android SDK:android-sdk_r04-windows

ADT:Android developer tools version 5

apache ant:apache-ant-1.8.1-bin

Android SDK的安装过程花了我不少的时间,开始我下载是的是android-2.1_r01-windows的版本,但是不知道为什么里面的tools目录下面很多程序不完整,在eclipse的windows->perferences->android下面设置sdk目录的时候提示找不到abd.exe等错误。不知道是什么原因。最后换了一个使用SDK setup.exe安装的sdk安装,期间也会遇到一个问题就是在他自己下载完tools_r05-windows.zip文件的时候解压后覆盖tools目录的时候出错


,需要手动覆盖,然后再重新运行SDK setup.exe才能顺利完成android SDK安装。

具体的配置和安装过程,网上很多:

android sdk 2.0 安装教程:http://topic.csdn.net/u/20091103/16/68c75d25-006c-432b-920e-59b79368aeec.html?4062

apache ant 下载地址:http://www.apache.org/dist/ant/binaries/

android模拟器运行界面:



HelloWorldAndroid

下面写一个简单的android程序:

新建一个android project,



这里的package name的命名规则还得是xxx.xxx.xx的形式,不然还不让你继续下一步。

android自动生成的目录结构:



在res/layout/main.xml中可以应用程序设计界面:



package cn.ac.gucas.liuxin;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyHelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.Button01);

button.setOnClickListener(new OnClickListener(){
public void onClick(View w){
openDialog();
}
});
}

private void openDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Hello World Android");
builder.setMessage("Hello World Android");
builder.setNegativeButton("OK", null);
builder.show();
}
}


用网上看的别人的代码试了一下。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: