我的第一个Android程序helloword及个人理解
2011-11-27 00:40
323 查看
第一次接触Android,自己写的代码,光搭建环境用了一天,先是在myeclipse9.0中,发现连接不了myeclipse官网,安装不了adt,郁闷,这天朝,连学习的网站也封
开始用代理,发现能上网站,但是更新不了插件,没办法,换成eclipse ,这东西绿色的,挺不错,第一个程序,鼓励一下吧
HelloWord代码:
main.xml代码:
定义文本和按钮,id分别为show和ok
这样,单击ok后文本出现helloword +现在的时间
另外,在开发中,必须在String。xml中配置所需的字符串,而不能在Activity中直接setText(‘单击我’) 这是不允许的
必须setText(R.id.具体id);
开始用代理,发现能上网站,但是更新不了插件,没办法,换成eclipse ,这东西绿色的,挺不错,第一个程序,鼓励一下吧
HelloWord代码:
public class HelloWorld extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置该Activity显示main.xml文件定义的View,及要使用的布局管理器 setContentView(R.layout.main); //R代表gen文件夹下系统自动生成的R.java用户不可以修改,保存的是所有的id Button bn = (Button)findViewById(R.id.ok); bn.setOnClickListener(new OnClickListener(){ //添加单击事件,单击按钮后文本变成指定的 public void onClick(View v) { final TextView show = (TextView)findViewById(R.id.show); show.setText("Hello Android~" + new java.util.Date()); } }); } }
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:id="@+id/show" android:layout_width="fill_parent" android:layout_height="wrap_content" 组件的高度为文字的高度 android:text="" /> <Button android:id="@+id/ok" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="单击我" /> </LinearLayout>
定义文本和按钮,id分别为show和ok
这样,单击ok后文本出现helloword +现在的时间
另外,在开发中,必须在String。xml中配置所需的字符串,而不能在Activity中直接setText(‘单击我’) 这是不允许的
必须setText(R.id.具体id);
相关文章推荐
- Android第一个程序:HelloWord
- Android 入门环境搭建第一个helloWord程序
- 创建第一个Android程序HelloWord
- Android的第一个程序--HelloWord
- Android开发之路之二------第一个程序HelloWord
- 第一个Android程序理解
- 第一个android程序:helloworld
- Android开发学习之三——第一个Android程序
- 搭建android开发环境,第一个android程序
- Android LBS App:春节在家无聊昨天忙活了一天,终于无师自学,开发了俺的第一个Android 程序
- Mono for Android: 利用mono for android开发的第一个程序
- 编写第一个Android程序
- delphi 10 Seattle 第一个Android程序
- Android应用之个人应用软件开发【全套程序展示及APK下载】
- 创建第一个Android程序
- 【Android开发】Android开发环境搭建----第一个Android程序Hello World(上)
- android菜鸟学习笔记5----第一个android程序
- android launchMode 加载模式 个人理解
- android 学习过程中登陆失效的个人理解
- java复习第四课,第一个程序HelloWord