今天是礼拜一,第一天学android。昨天放假的时候在家整开发环境,整了几个小时。今天去学校,轻松了许多。不过,还是有些小小的心得和体会。好吧,既然叫了android日记,那就开始吧。

从开始搭建android的开发环境开始吧,其实搞清楚了很简单,没有那么的复杂。

所需文件是:android-sdk-2.3

eclipse-3.5-正式版

jdk-1.6-win32

装好sdk,进入eclipse里面,点击help,install new software安装android插件。

然后就可以新建android工程了。

src-------用户的源代码

gen------插件自动维护的,用于存放资源索引的。

assets--------插件自动生成,用户把程序打包成apk的文件,并交个android虚拟机安装运行。

res-------包含需要的字符串文件和前台布局文件----------本文件夹一定要注意,里面的文件名称绝对不能用大写,如果用了大写就会报莫名奇妙的错误。

/HelloAndroid/AndroidManifest.xml --------------- 配置程序入口的xml文件

ok,明白了android的文件夹类型及意义,

我就写了个android程序吧。。。。。。。。。

Hello_World

import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class Hello_World extends Activity {    /** Called when the activity is first created. */  private EditText usernameText;private Button loginBtn;  @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);//设定main.xml为本activity类的前台类,暂且这样称呼他..        usernameText=(EditText)findViewById(R.id.username_field);//根据id拿到EditText对象        loginBtn=(Button)findViewById(R.id.sureBtn);//根据id拿到Button对象        loginBtn.setOnClickListener(new View.OnClickListener() {//监听@Overridepublic void onClick(View v) {//方法String username=usernameText.getText().toString().trim();Intent it=new Intent(Hello_World.this,MyActivity.class);//intent对象使用来实现两个类之间通信的it.putExtra("loginname", username);//传递username参数给MyActivity类startActivity(it);//启动本intent对象}});    }}
package com.tan.hello;
import android.app.Activity;import android.os.Bundle;import android.widget.TextView;
public class MyActivity extends Activity {
@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.my_activity);//以my_activity.xml为本类的前台类String loginname=this.getIntent().getStringExtra("loginname");//拿到传过来的username的值TextView showname=(TextView)findViewById(R.id.showView);//将其显示showname.setText(loginname);}}
main.xml内容
<?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" ><TextView  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:text="@string/username"//在string.xml中拿到username的值,以下同理 /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/username_field" /> <TextView  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:text="@string/password" />  <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/password_field" android:password="true" /> <Button android:id="@+id/sureBtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/sure" /> <Button android:id="@+id/concelBtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/concel" /></LinearLayout>
my_activity.xml内容
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/showView" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout>
String.xml内容
<?xml version="1.0" encoding="utf-8"?><resources> <string name="username">用户名:</string> <string name="app_name">腾讯QQ</string> <string name="password">密码:</string> <string name="sure">确定</string> <string name="concel">取消</string></resources>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tan.hello" android:versionCode="1" android:versionName="1.0">
/HelloAndroid/AndroidManifest.xml内容
 <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Hello_World" android:label="@string/app_name">//程序的名称 <intent-filter>//在activity配置中出现这个表示程序从该类启动 <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MyActivity" android:label="@string/app_name"> </activity>
 </application></manifest>

更多相关文章

  1. Android 应用程序中使用 Internet 数据(XML、JSON 和 protocol bu
  2. PHP开发Android应用程序
  3. Android应用程序核心-应用程序的基本组件
  4. Android语音便签快速调用-内置录音程序
  5. android小功能实现之xml文件解析(Pull)
  6. android Parcelable接口序列化对象
  7. android中下载文件到sdcard和进度条小结
  8. Android R文件丢失解决办法
  9. Android init.rc文件解析过程分析

随机推荐

  1. 利用androidannotations的@Rest注解替换S
  2. Android 技术专题系列之五 -- 本地化
  3. 问题1.Activity为什么开始要调用onCreate
  4. Android界面布局基本属性
  5. 使用ListActivity得到ListView
  6. ListView的使用2
  7. 沃邮箱Android客户端产品体验报告
  8. Android NDK移植libiconv和libxml2
  9. Eclipse 环境下安装PhoneGap开发插件
  10. Android - bitmap简单总结