Android之旅--初识安卓

 

安装开发环境

 

     1.下载SDK。

        我用的是android安装包,里面有个manager自动帮助下载相关SDK,省去了不少麻烦!下载地址:开发包

     2.安装ADT(eclipse的android插件)

        启动Eclipse,选择【Help】 > 【Soft Updates】 > 【Find and Install…】

        选择“Available Software”标签页,点击【Add Site…】按键。添加update站点:https://dl-ssl.google.com/android/eclipse/

        这时窗口中新增了“https://dl-ssl.google.com/android/eclipse/”项,选中该项,点击【Install…】按键即可下载。

        (MyEclipse也差不多,都是在Help里面)

 

     我安装后遇到的问题:

          在新建android项目的时候老是提示我android的环境没有安装,我就郁闷了。原因如下图所示,另外需要注意的是sdk的路径中不要有中文,否则有错误。

2010-11-23_200448

 

上面的都安装完成后就可以新建一个项目了。

 

第一个android程序

        参照网上的例子写了一个简单的例子。结构如下:

结构

 

 

     首先改写res->layout->main.xml,这个文件有点像wpf/silverlight下面的xaml文件,是用来配置布局的。内容如下:

代码
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    >
    <EditText android:text="EditText01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/edtInput"></EditText>  
    <LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center">  
         <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show" android:id="@+id/btnShow"></Button>  
         <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Clear" android:id="@+id/btnClear"></Button>  
    </LinearLayout>  
</LinearLayout>  

 

布局是这样的:最上面是一个EditText输入框,然后下面是用LinearLayout布局的两个按钮,分别用来显示和清楚里面的内容。然后,写Test.java里面的程序:

代码
public class Test extends Activity
{
	/** Called when the activity is first created. */

	Button btnShow;
	Button btnClear;
	EditText edtInput;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		btnShow = (Button) findViewById(R.id.btnShow);// 控件与代码绑定
		btnClear = (Button) findViewById(R.id.btnClear);// 控件与代码绑定
		edtInput = (EditText) findViewById(R.id.edtInput);// 控件与代码绑定
		btnShow.setOnClickListener(new ClickListener());// 使用点击事件
		btnClear.setOnClickListener(new ClickListener());// 使用点击事件
	}

	class ClickListener implements OnClickListener
	{
		public void onClick(View v)
		{
			if (v == btnShow)
			{
				new AlertDialog.Builder(Test.this).setIcon(
						android.R.drawable.ic_dialog_alert).setTitle(
						"Information").setMessage(edtInput.getText()).show();
			}
			else if (v == btnClear)
			{
				edtInput.setText("HelloAndroid");
			}
		}
	}
}

 

代码比较简单,就是初始化的时候初始化一下布局里面声明的view(相当于winform里面的一个control),声明两个按钮的点击事件(和winform有点不一样啊,多接触就习惯了吧)。运行效果如下:

效果1 效果2

 

具体代码里面是如何运行的,各个类又是什么意思这里先不说了(我还没研究呢^_^)!以后一步一步来吧……

转载于:https://www.cnblogs.com/qianlifeng/archive/2010/11/23/1885862.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值