import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;public class MainActivity extends AppCompatActivity {@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main);}
}
2.activity_main <?xml version="1.0" enCoding="utf-8"?> <androIDx.constraintlayout.Widget.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="190dp" androID:layout_height="133dp" androID:text="Hello World!于鲲洋20192314 \n前一人20192313 \n后一人20192315" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintleft_toleftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constrainttop_totopOf="parent" /> </androIDx.constraintlayout.Widget.ConstraintLayout>
3.运行截图
2.Activity测试参考《Java和AndroID开发学习指南(第二版)(EPUBIT,Java for AndroID 2nd)》第二十五章:构建项目,运行教材相关代码创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity1.代码
import androIDx.appcompat.app.AppCompatActivity;
import androID.content.Intent;
import androID.os.Bundle;
import androID.vIEw.VIEw;
import androID.Widget.button;
public class MainActivity extends AppCompatActivity {
private button Go;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); Go = findVIEwByID(R.ID.textGo); Go.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { //跳转到ThirdActivity演示界面 Intent intent = new Intent(MainActivity.this, ThirdActivity.class); startActivity(intent); } });}
}
import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.Widget.TextVIEw;public class ThirdActivity extends AppCompatActivity { private TextVIEw textVIEw; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_third); textVIEw = findVIEwByID(R.ID.textGo);}
}
2.运行截图3.UI测试参考《Java和AndroID开发学习指南(第二版)(EPUBIT,Java for AndroID 2nd)》第二十六章:构建项目,运行教材相关代码修改代码让Toast消息中显示自己的学号信息1.程序代码
<?xml version="1.0" enCoding="utf-8"?><androIDx.constraintlayout.Widget.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"><button androID:ID="@+ID/button1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="呵呵" androID:textcolor="#FFFFFF" androID:textSize="72sp" app:backgroundTint="#D13B3B" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constrainttop_totopOf="parent" />textVIEw.setTextSize(500);</androIDx.constraintlayout.Widget.ConstraintLayout>import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.Toast;public class MainActivity extends AppCompatActivity {@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); //在onCreat中设置一个button类的对象bt,并用findVIEwByID将它指向我们在布局中创建好的button button bt=(button)findVIEwByID(R.ID.button1); //调用button类的setonClickListener方法来创建一个监听器 bt.setonClickListener(new VIEw.OnClickListener() { //重写onClick方法来定义点击button后的活动 @OverrIDe public voID onClick(VIEw v) { //直接用Toast和它的makeText方法来创建一个Toastd窗 Toast.makeText(MainActivity.this,"20192314于鲲洋",Toast.LENGTH_SHORT).show(); } });}
}
2.运行截图4.布局测试:参考《Java和AndroID开发学习指南(第二版)(EPUBIT,Java for AndroID ###2nd)》第二十七章:构建项目,运行教材相关代码修改布局让P290页的界面与教材不同运行截图
5.事件处理测试:参考《Java和AndroID开发学习指南(第二版)(EPUBIT,Java for AndroID ###2nd)》第二十八章:构建项目,运行教材相关代码提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分1.程序代码
<application androID:allowBackup="true" androID:icon="@mipmap/ic_launcher" androID:label="@string/app_name" androID:roundIcon="@mipmap/ic_launcher_round" androID:supportsRtl="true" androID:theme="@style/theme.Text5"> <activity androID:name=".MainActivity"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity></application>
<AnalogClock androID:ID="@+ID/analogClock1" androID:layout_wIDth="201dp" androID:layout_height="175dp" androID:layout_alignParenttop="true" androID:layout_margintop="485dp" androID:onClick="changecolor" />
####2.运行截图![](https://www.icode9.com/i/l/?n=20&i=blog/2147066/202011/2147066-20201104221528957-1310067509.jpg)![](https://www.icode9.com/i/l/?n=20&i=blog/2147066/202011/2147066-20201104221534143-1912016934.jpg)#遇到的问题###1.AS中的虚拟设备在下载之后依然无法使用,最终选择在网络上搜索教程,将手机连接到电脑上,打开USB调试,直接在手机上进行实验###2.有时候手机应用中无法显示文件的名字,发现当继承的不是AppCompatActivity类而是Activity类,不会显示应用名称。使MainActivity继承AppCompatActivity类即可#心得体会###AndroID第一次做实验,基本上啥也不会,打开之后那么多文件总共就认得出一个java文件,其余的无论是用途还是语法完全没见过。单是前期调试虚拟设备就让我十分崩溃,下载不断失败,不断retry,最终下好之后发现还是用不了,不得已尝试着将真手机连接在电脑上,勉强将实验进行下去了。Andriod比我想象的复杂的多,很多知识还需要在今后不断学习不断巩固。 总结 以上是内存溢出为你收集整理的学号20192314 2020-2021-1 《数据结构与面向对象程序设计》实验五报告全部内容,希望文章能够帮你解决学号20192314 2020-2021-1 《数据结构与面向对象程序设计》实验五报告所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)