实验三 Android程序设计

实验三 Android程序设计

课程:Java程序设计

班级:1652

姓名:孔月

学号:20165208

指导教师:娄嘉鹏

实验日期:2018.5.14

实验名称:Android程序设计

实验要求:

  1. 没有Linux基础的同学建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程;
  2. 完成实验、撰写实验报告,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法如“查网络”、“问同学”、“看书”等一律得0分)以及分析(从中可以得到什么启示,有什么收获,教训等);
  3. 实验报告中统计自己的PSP(Personal Software Process)时间;
  4. 严禁抄袭。

    实验内容、步骤与体会

目录:

  • (一)安装认识Android
  • (二)活动
  • (三)Toast
  • (四)布局测试
  • (五)事件处理测试

(一)安装认识Android

  • 安装 Android Stuidio
  • 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号
  • 学习Android Stuidio调试应用程序
  • 将activity_main.xml中的android:text="Hello World!"中的Hello World改成"Hello World!20165208\n 20165207\n 20165209\n"
  • 完整代码如下
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!20165208\n  20165207\n 20165209\n"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
  • 实验效果截图如下

返回目录

(二)活动

  • 构建项目,运行教材相关代码
  • 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class MainActivity extends Activity implements
    OnTouchListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = (TextView) findViewById(R.id.textView1);
        tv.setOnTouchListener(this);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it
// is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onTouch(View arg0, MotionEvent event) {
        Intent intent = new Intent(this, ThirdActivity.class);
        intent.putExtra("message", "20165208 孔月");
        startActivity(intent);
        return true;
    }
}

代码运行截图如下

返回目录

(三)Toast

  • 构建项目,运行教材相关代码
  • 修改代码让Toast消息中显示自己的学号信息
  • 具体代码如下

activity_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.lxkj.commitzyq3.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="20165230"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintHorizontal_bias="0.318"
        app:layout_constraintVertical_bias="0.226" />
    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteY="16dp"
        tools:layout_editor_absoluteX="5dp" />

</android.support.constraint.ConstraintLayout>

MainActivity.java

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.util.AttributeSet;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnshow1=(Button) findViewById(R.id.btn1);
        btnshow1.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v){
                Toast toast = Toast.makeText(MainActivity.this,"20165208 孔月", Toast.LENGTH_LONG);
                toast.show();

            }
        });
    }

最终运行效果如图

返回目录

(四)布局测试

  • 构建项目,运行教材相关代码
  • 修改布局让P290页的界面与教材不同
  • 具体代码如下
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="2dp"
    android:paddingRight="2dp">
    <Button
        android:id="@+id/cancelButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="20165208"
        android:layout_marginTop="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    <Button
        android:id="@+id/saveButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="孔月"
        android:layout_below="@+id/cancelButton"
        android:layout_alignLeft="@+id/cancelButton"
        android:layout_alignStart="@+id/cancelButton"
        android:layout_marginTop="23dp" />
    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_marginTop="45dp"
        android:padding="4dp"
        android:src="@android:drawable/ic_dialog_email"
        android:id="@+id/imageView"
        android:layout_below="@+id/saveButton"
        android:layout_centerHorizontal="true" />
    <LinearLayout
        android:id="@+id/filter_button_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center|bottom"
        android:background="@android:color/white"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/filterButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Filter" />
        <Button
            android:id="@+id/shareButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Share" />
        <Button
            android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Delete" />
    </LinearLayout>
    </RelativeLayout>

    运行截图如下

    返回目录

    (五)事件处理测试

  • 构建项目,运行教材相关代码
  • 具体代码如下

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dell1.helloworld"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name="com.example.dell1.helloworld.MainActivity"
            android:label="@string/app_name">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

  • 简要调整后,运行效果如图

问题总结与体会

  • 问题1:本次实验安装Android Stuidio上遇到了很多困难,先是并没有如老师的步骤所写的自动弹出sdk安装界面,但是后续操作中又显示已经安装。应该是对安装过程没有产生大的影响
  • 问题2:在安装结束需要安装插件时,多次点击try again无任何反应,均显示failed

  • 解决方案:是最初下载的gradle安装包有问题,进行替换后即可正常安装。
  • 问题3:接下来的安装我遇到了最大的问题,显示提示无法找到sdk,但是在sdk安装路径中我又可以看到它已经安装并使用,后发现所设定的手机无法使用,具体问题如下图,在删去手机重新设置无效后,我上网查找了问题,网上给出的解决方案如下图,多次矫正后都无法正确运行,后又卸载安装了三次还是无法运行,也有询问过同学助教还是无法解决这个问题。。。

  • 暂时的解决方法:

  • 体会:本次实验对我来说有点难,从安装开始遇到问题,这个问题持续到后来也没有解决,是真的不知道干怎么解决了,网上查到的相近的问题解决方案都进行了尝试,然而并没有任何效果,也进行了卸载安装,但是再开启时还是同样的问题,于是后来在助教学姐的建议下我选择了借用同学的电脑完成此次实验。
步骤 耗时 百分比
需求分析 25 min 8.3%
设计 70 min 23.3%
代码实现 120 min 40%
测试 40 min 13.3%
分析总结 45 min 15%

原文地址:https://www.cnblogs.com/KY-high/p/9065132.html

时间: 2024-07-31 04:44:25

实验三 Android程序设计的相关文章

20172328《程序设计与数据结构》实验四 Android程序设计报告

20172328<程序设计与数据结构>实验四 Android程序设计报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 李馨雨 学号:20172328 实验教师:王志强老师 实验日期:2018年6月1日 必修选修: 必修 一.实验内容 实验1:Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)>第二十四章: 参考http://www.cnblogs.com/

20165232第4次实验《Android程序设计》实验报告

20165232第4次实验<Android程序设计>实验报告 一.实验报告封面 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:何彦达 学号:20165232 指导教师:娄嘉鹏 实验日期:2018年5月14日 实验时间:15:35 - 17:15 实验序号:实验四 实验名称:Android程序设计 二.实验内容 实验四 Android程序设计-1 实验要求 Android Stuidio的安装测试:参考<Java和Android开发学习指南(第二版)(EPUBIT,Ja

2017-2018-2 20165233 实验四 Android程序设计

20165233 实验四 Android程序设计 实验内容 任务一: 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Studio 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分 学习Android Stuidio调试应用程序 任务二: 构建项目,运行教材相关代码 创建 Th

20165313Java实验四 Android程序设计

实验报告封面 课程:Java程序设计 班级:1653班 姓名:张晨晖 学号:20165313 指导教师:娄嘉鹏 实验日期:2018年5月14日 实验时间:13:45 - 15:25 实验序号:实验四 实验名称:Android程序设计 实验内容及步骤 实验一 :Android Stuidio的安装测试 1.试验要求: 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio 完成Hello World,

2018-2019-1 20165212 实验三-并发程序设计

2018-2019_20165212_20165222_20165313<信息安全系统设计基础>实验三报告 任务一 C语言模拟wc命令.实现linux下客户端服务器文件通信 使用man wc命令查看wc命令的基本用法: 可知wc命令的功能为:统计指定文件中的字节数.字数.行数等,并将统计结果显示输出.常用的参数为: -c:统计字节数 -l:统计行数 -m:统计字符数,且不能与-c参数一起使用 -w:统计字数,一个字被定义为由空白.跳格或换行字符分割的字符串 -L:打印最长行的长 但是,如果我们

20165309 实验四 Android程序设计

2017-2018-2 20165309实验四<Java面向对象程序设计>实验报告 一.实验内容 1.Android Studio的安装测试 2.Activity测试 3.UI测试 4.布局测试 5.事件处理测试 二.实验步骤 1.完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号 如图,找到activity_main.xml 点黄框里左侧的Design 在右边找到这里,输入实验要求的内容 结果如下: 2.创建 Thi

实验四 Android程序设计

Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)>第二十四章: - 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio - 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号,提交代码运行截图和码云Git链接,截图

20165332实验四 Android开发基础

20165332 实验四 Android程序设计 一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:延亿卓 学号:20165332 指导教师:娄嘉鹏 实验日期:2018年5月14日 实验时间:13:45 - 3:25 实验序号:实验四 实验名称:Android程序设计 实验要求: 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器> 课程 完成实验.撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具

2017-2018-2 20165312 实验四《Android程序设计》实验报告

2017-2018-2 20165312 实验四<Android程序设计>实验报告 一.安装Android Studio并进行Hello world测试和调试程序 安装Android Studio 可以参考娄老师的博客Android开发简易教程或者参考<Java和Android开发学习指南>第二十四章,里面都有详细步骤,一步一步来就很简单~ 新建一个project项目后,project窗口主要有两个主要的节点:app和Gradle Scripts.app节点中包含了应用程序中所有的