Android studio入门到精通实例实验

实验内容:

----------------- 简单的考试程序----------------

实验步骤:

一、打开Android studio,新建一个项目;


二、写入代码;

<?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">

<TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Android基础知识测评"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintHorizontal_bias="0.498"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.058" /><EditTextandroid:id="@+id/et_on"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="16dp"android:ems="3"android:inputType="textPersonName"app:layout_constraintBottom_toBottomOf="@+id/textView"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="@+id/textView"app:layout_constraintVertical_bias="0.615"android:layout_marginLeft="16dp" /><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="@string/di1ti"app:layout_constraintStart_toEndOf="@+id/et_on"app:layout_constraintTop_toBottomOf="@+id/textView2" /><TextViewandroid:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="@string/di2ti"app:layout_constraintStart_toStartOf="@+id/et_on"app:layout_constraintTop_toBottomOf="@+id/textView" /><RadioGroupandroid:id="@+id/radioGroup"android:layout_width="113dp"android:layout_height="64dp"app:layout_constraintStart_toStartOf="@+id/textView3"app:layout_constraintTop_toBottomOf="@+id/textView3"><RadioButtonandroid:id="@+id/rd1"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="开源的" /><RadioButtonandroid:id="@+id/rd2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="非开源的" />
</RadioGroup><TextViewandroid:id="@+id/textView4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="@string/di3ti"app:layout_constraintStart_toStartOf="@+id/textView3"app:layout_constraintTop_toBottomOf="@+id/radioGroup" /><CheckBoxandroid:id="@+id/cb2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="60dp"android:text="JAVA"app:layout_constraintStart_toEndOf="@+id/cb1"app:layout_constraintTop_toBottomOf="@+id/textView4"android:layout_marginLeft="60dp" /><CheckBoxandroid:id="@+id/cb1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="JDK"app:layout_constraintStart_toStartOf="@+id/textView4"app:layout_constraintTop_toBottomOf="@+id/textView4" /><CheckBoxandroid:id="@+id/cb3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="60dp"android:text="SDK"app:layout_constraintStart_toEndOf="@+id/cb2"app:layout_constraintTop_toBottomOf="@+id/textView4"android:layout_marginLeft="60dp" /><TextViewandroid:id="@+id/textView5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="@string/di4ti"app:layout_constraintStart_toStartOf="@+id/textView4"app:layout_constraintTop_toBottomOf="@+id/cb1" /><Spinnerandroid:id="@+id/spinner"android:layout_width="130dp"android:layout_height="30dp"android:entries="@array/Systems"app:layout_constraintStart_toStartOf="@+id/textView5"app:layout_constraintTop_toBottomOf="@+id/textView5" /><TextViewandroid:id="@+id/textView6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="104dp"android:layout_marginBottom="36dp"android:text="总分:"app:layout_constraintBottom_toTopOf="@+id/button"app:layout_constraintStart_toStartOf="parent"android:layout_marginLeft="104dp" /><TextViewandroid:id="@+id/sorce"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#F1ED06"android:text="   00   "app:layout_constraintBottom_toBottomOf="@+id/textView6"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.025"app:layout_constraintStart_toEndOf="@+id/textView6"app:layout_constraintTop_toTopOf="@+id/textView6"app:layout_constraintVertical_bias="0.0" /><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="20dp"android:text="@string/subscribe"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.a37;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton;

public class MainActivity extends AppCompatActivity {
static int i = 0,cb_num = 0;
boolean rd_num = false,sp_num = false,et_num = false;
TextView sorce;
TextView et_on;
RadioGroup rd;
Button button;
CheckBox checkBox1;
CheckBox checkBox2;
CheckBox checkBox3;

@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//定义et_on = findViewById(R.id.et_on);sorce = findViewById(R.id.sorce);rd = findViewById(R.id.radioGroup);button = findViewById(R.id.button);checkBox1 = findViewById(R.id.cb1);checkBox2 = findViewById(R.id.cb2);checkBox3 = findViewById(R.id.cb3);//为每个复选按钮设置状态改变监听器checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked) cb_num++;else cb_num--;}});checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked) cb_num--;else cb_num++;}});checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked) cb_num++;else cb_num--;}});//设置单选按钮组添加事件监听rd.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {//获取被选择的单选按钮RadioButton r = (RadioButton) findViewById(checkedId);if(r.getText().equals("开源的")) rd_num = true;else rd_num = false;}});//edittext监听et_on.setOnEditorActionListener(new TextView.OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {if(et_on.getText().toString().equals("2")) et_num = true;else et_num = false;return false;}});//获取下拉列表对象final Spinner spinner = (Spinner) findViewById(R.id.spinner);//为Spinner添加选择监听器spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {@Override//数据选择事件处理public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {String[] Systems = getResources().getStringArray(R.array.Systems);//显示选择结果if(Systems[pos].equals("Linux")) sp_num = true;else sp_num = false;}//以下方法重写必须有@Overridepublic void onNothingSelected(AdapterView<?> parent) {// Another interface callback}});button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(cb_num == 2) i++;if(sp_num) i++;if(et_num) i++;if(rd_num) i++;sorce.setText("   "+(i*50)+"   ");if(i == 4)Toast.makeText(MainActivity.this,"你真棒!祝贺你!", Toast.LENGTH_SHORT).show();else if(i == 2)Toast.makeText(MainActivity.this,"成绩合格!", Toast.LENGTH_SHORT).show();elseToast.makeText(MainActivity.this,"成绩不合格!", Toast.LENGTH_SHORT).show();}});
}

}

<string name="app_name" translatable="false">zuoye06_231</string>
<string name="di1ti" translatable="false">选择题</string>
<string name="di2ti" translatable="false">Android操作系统是(50分)</string>
<string name="di3ti" translatable="false">Android Studio 开发Android程序,还需安装:(    )(50分)</string><string name="subscribe" translatable="false">提交</string>
<string name="di4ti" translatable="false">" "</string>

三、运行结果截图:
1、(打开程序界面)

2、(回答错误界面)

3、(通过考试界面)

到此本次实验完成!

Android studio入门到精通实例实验相关推荐

  1. Android Volley入门到精通:初识Volley的基本用法

    1. Volley简介 我们平时在开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进行H ...

  2. ArcGIS10从入门到精通系列实验图文教程(附配套实验数据持续更新)

    文章目录 1. 专栏简介 2. 专栏地址 3. 专栏目录 1. 专栏简介 本教程<ArcGIS从入门到精通系列实验教程>内容包括:ArcGIS平台简介.ArcGIS应用基础.空间数据的采集 ...

  3. android+studio入门指南+pdf,android+studio使用指南v0.1.pdf

    androidstudio使用指南v0.1 <Android Studio入门指南>作者:毕小朋 博客:/wirelessqa Android Studio入门指南v0.1 作者:毕小朋 ...

  4. Android自定义控件入门到精通--Region区域

    <Android自定义控件入门到精通>文章索引 ☞ https://blog.csdn.net/Jhone_csdn/article/details/118146683 <Andro ...

  5. Android自定义控件入门到精通--View树的布局

    <Android自定义控件入门到精通>文章索引 ☞ https://blog.csdn.net/Jhone_csdn/article/details/118146683 <Andro ...

  6. 《Android从入门到精通》家庭理财通

    闲着没事把<Android从入门到精通>最后的项目给写了.以下是该项目的各文件之间的关联. 我把书上没写的那一部分,就是OutAccount部分代码补齐了(因为书后面的光盘没有了,所以只能 ...

  7. Android自定义控件入门到精通--View树的测量流程

    <Android自定义控件入门到精通>文章索引 ☞ https://blog.csdn.net/Jhone_csdn/article/details/118146683 <Andro ...

  8. android从入门到精通pdf 明日科技

    android从入门到精通pdf 明日科技 链接: https://pan.baidu.com/s/1dGSkbCl 密码: wpaa (失效) 链接:https://pan.baidu.com/s/ ...

  9. Android studio 下 JNI 开发实例

    在AS中进行 NDK 开发之前,我们先来简单的介绍几个大家都容易搞懵的概念: 到底什么是JNI,什么是NDK? 何为"交叉编译"? 先看什么是 JNI?JNI 的全称就是 Java ...

最新文章

  1. os:进程与线程问题
  2. Jupyter Nodebook添加代码提示(Vscode配置Jupyter Notebook运行.ipynb文件)
  3. Windows下使用Notepad++修改二进制文件,exe可执行文件
  4. shell脚本(五)——函数的格式、传参、变量、递归、函数库
  5. 一个数据包大小是多少k_算法交流: 6046 数据包的调度机制 【2.6基本算法之动态规划】...
  6. python运行命令_对python中执行DOS命令的3种方法总结
  7. 宏基因组大数据分析的质量控制流程规范
  8. 麒麟810加持,华为nova 5z让你一步从青铜变王者
  9. PKU/POJ 2054 Color a Tree
  10. Report Machine使用方法
  11. HDU 5144 NPY and shot(三分法)
  12. 【uniapp】索引列表展示更多信息
  13. CCF:201712-4 行车路线
  14. 伦敦银xag是什么意思?
  15. 从C++转向Rust:两大主题值得关注!
  16. 程序猿生存指南-22 分手快乐
  17. 不同网段无法访问共享文件夹的解决办法
  18. 2005年中兴软件校园招聘笔试题
  19. 串口;电脑连接串口;为啥需要/保留串口
  20. Python那些功能哟

热门文章

  1. 谷歌PR值停止更新的影响
  2. Sublime Text使用技巧
  3. Unity - URP RenderFeature - 实现类似多 Pass 的 XRay: Rim、Pattern
  4. CORDIC算法计算复数相位角(含verilog源码)
  5. 文件的打开和关闭,fopen()和fclose
  6. 从实际应用角度浅析SAP仓库中的过账变更功能
  7. 如何利用AI技术在零售业做产品创新——京东无人超市的成长之路
  8. 3441. 唐纳德与子串 (Easy)
  9. 直播、点播系统开发项目总结(本地视频、抓包视频、直播推流、网络直播、平台搭建等相关问题点记录)
  10. Git 储藏(stash)详解