学校跟着潮流也开起了android的课程、学了点皮毛后、来实际操作下。写博客的目的是为了以后能再回过头看看细节方面的实现。。。。

建一个Sample01Activity,代码如下:

        
  1. importandroid.app.Activity;
  2. importandroid.os.Bundle;
  3. importandroid.view.*;
  4. importandroid.content.Intent;
  5. importandroid.view.View.OnClickListener;
  6. importandroid.widget.*;
  7. publicclassSample01ActivityextendsActivity{
  8. /**Calledwhentheactivityisfirstcreated.*/
  9. @Override
  10. publicvoidonCreate(BundlesavedInstanceState){
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.main);
  13. setTitle("androidworld");TextViewmyTextView=(TextView)findViewById(R.id.myTextView);
  14. myTextView.setText("点击下面的按钮进入另一个界面");
  15. ButtonmyButton=(Button)findViewByI(R.id.myButton);
  16. myButton.setText("点击此处");
  17. myButton.setOnClickListener(newMyButtonListener());
  18. }
  19. classMyButtonListenerimplementsOnClickListener{
  20. publicvoidonClick(Viewv){
  21. Intentintent=newIntent();
  22. intent.setClass(Sample01Activity.this,Other.class);
  23. Sample01Activity.this.startActivity(intent);
  24. }
  25. }
  26. }

上述代码的关键是按钮事件的实现(Intent 的作用)

第一个界面:

界面实现:main.xml代码

        
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical"
  6. >
  7. <TextView
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:id="@+id/myTextView" />"
  11. <Button
  12. android:id="@+id/myButton"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. ></Button>
  16. </LinearLayout>

点击按钮后、要使它能跳转到下一个界面,需再新建一个activity:

        
  1. importandroid.app.Activity;
  2. importandroid.os.Bundle;
  3. importandroid.widget.*;
  4. publicclassOtherextendsActivity{
  5. privateTextViewnewTextView=null;
  6. @Override
  7. protectedvoidonCreate(BundlesavedInstanceState){
  8. //TODOAuto-generatedmethodstub
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.other);
  11. setTitle("新天地");
  12. newTextView=(TextView)findViewById(R.id.newTextView);
  13. newTextView.setText("hi,hereiswhereyouwanttogo!");
  14. }
  15. }

同样为新的activity建一个layout:

        
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical"
  6. >
  7. <TextView
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:id="@+id/newTextView"/>"
  11. </LinearLayout>

此时基本工作已经完成,当运行的时候、结果却不是预料之中的、这时我们还需要很主要的一步,就是每新建一个activity时都要到androidmanifest注册一下:

        
  1. <activityandroid:name=".Other"
  2. android:label="Other">
  3. </activity>
  4. plication>

这个时候才是真正的大功告成,点击按钮后的界面:

(ok,基本完成,下一步准备实现页面跳转的效果、因为就这样感觉好死板。。奋斗)

更多相关文章

  1. android 纯代码 详细编写布局文件
  2. Android(安卓)2.2 r1 API 中文文档系列(11) —— RadioButton
  3. Android时间计时器
  4. [Android(安卓)Studio]设置Button的圆角、点击效果、按钮颜色
  5. android之IntentFilter的用法_Intent.ACTION_TIME_TICK在manifes
  6. RxJava的个人概述
  7. 使用java语言中的注解生成器生成代码
  8. android实现点击按钮切换不同的fragment布局
  9. Android-NDK开发之基础--Android(安卓)JNI实例代码(三)-- 在JNI

随机推荐

  1. python 核心编程第六章课后题自己做的答
  2. 使用python脚本配置zabbix发送报警邮件
  3. Python PyV8安装测试(Win7)
  4. Python引起的混乱解决之道——感悟
  5. 使用Python操作MongoDB
  6. Python第十天 print >> f,和fd.write()的
  7. 如何用位于括号外的逗号分隔字符串?
  8. 数组与矩阵---需要排序的最短子数组长度
  9. 如何为Google Cloud Endpoints方法生成py
  10. pyuthon高级技巧2