电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

android studio實現簡單考試應用程序實例代碼詳解

瀏覽:2日期:2022-09-25 09:20:52

一、問題

1、如圖所示,設計一個包含四種題型的簡單考試應用程序(具體考試題目可以選用以下設計,也可以自己另外確定),項目名稱:zuoye06_666 ;(666,改成自己的實際編號)。

2、布局管理器任選(約束布局相對容易實現)。

3、“提交”按鈕的Text通過字符串資源賦值,不要直接輸入“提交”兩個字。

4、每題按25分計算,編寫相應的程序,答題完成后單擊“提交”按鈕,在“總得分:”右邊文本框中顯示實際得分;同時,顯示一個Toast消息框:

答對不足3題,顯示:“還需努力啊!”;

答對3題,顯示:“祝賀你通過考試!”;

全部答對,顯示:“你真棒!祝賀你!”

android studio實現簡單考試應用程序實例代碼詳解

二、分析

1.這次作業比較簡單,就是上課講的東西的集合,練習spinner、checkbox、radiobutton、edittext以及button的監聽,還有setText和Toast用法。

2.注意點,要考慮到正常考試的時候學生第一次選對后來改錯,或者一開始選錯后來改對的情況,考生的分數應該由最后一次監聽到結果來確定,所以添加了boolean類型的以及checkbox的計數。

三、代碼

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'> <TextView android: 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' /> <EditText android: 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' /> <TextView android: 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' /> <TextView android: 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' /> <RadioGroup android: android:layout_width='113dp' android:layout_height='64dp' app:layout_constraintStart_toStartOf='@+id/textView3' app:layout_constraintTop_toBottomOf='@+id/textView3'> <RadioButton android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='開源的' /> <RadioButton android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='非開源的' /> </RadioGroup> <TextView android: 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' /> <CheckBox android: 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' /> <CheckBox android: 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' /> <CheckBox android: 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' /> <TextView android: 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' /> <Spinner android: android:layout_width='130dp' android:layout_height='30dp' android:entries='@array/Systems' app:layout_constraintStart_toStartOf='@+id/textView5' app:layout_constraintTop_toBottomOf='@+id/textView5' /> <TextView android: 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' /> <TextView android: 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' /> <Button android: 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>

2.strings.xml

<resources> <string name='app_name'>zuoye06_231</string> <string name='di1ti'>年11月5日,Google發布安卓系統(答:2007)</string> <string name='di2ti'>Android操作系統是(答:開源的)</string> <string name='di3ti'>Android Studio 開發Android程序,還需安裝:(1、3)</string> <string name='di4ti'>Android是基于?平臺手機的操作系統(Linux)</string> <string name='subscribe'>提交</string></resources>

3.Systems.xml

<?xml version='1.0' encoding='utf-8'?><resources> <string-array name='Systems'> <item>Windows</item> <item>Linux</item> <item>Mac</item> </string-array></resources>

4.java代碼

package com.example.lenovo.zuoye06_231; 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(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) cb_num++; else cb_num--; } }); checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) cb_num--; else cb_num++; } }); checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) cb_num++; else cb_num--; } }); //設置單選按鈕組添加事件監聽 rd.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public 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() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if(et_on.getText().toString().equals('2007')) 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; } //以下方法重寫必須有 @Override public void onNothingSelected(AdapterView<?> parent) { // Another interface callback } }); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(cb_num == 2) i++; if(sp_num) i++; if(et_num) i++; if(rd_num) i++; sorce.setText(' '+(i*25)+' '); if(i == 4) Toast.makeText(MainActivity.this,'你真棒!祝賀你!', Toast.LENGTH_SHORT).show(); else if(i == 3) Toast.makeText(MainActivity.this,'祝賀你通過考試!', Toast.LENGTH_SHORT).show(); else Toast.makeText(MainActivity.this,'還需努力啊!', Toast.LENGTH_SHORT).show(); } }); }}

四、結論

1.當用戶填寫的時候最終答案是按最后修改的來確定的。

2.考慮到正常情況下當用戶提交后數據已經上傳到網絡上,所以沒有添加不能二次修改的代碼,因此測試的時候會出現第一次提交后不退出,修改后結果會出問題。

五、參考文章

3.29更新如果想要解決不能2次修改問題可以加一個狀態標志符。

如果想要解決二次提交后累加的問題,可以在Toast后加一個i=0。

到此這篇關于android studio實現簡單考試應用程序的文章就介紹到這了,更多相關android studio實現 考試應用程序內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Android
相關文章:
主站蜘蛛池模板: 大巴租车平台承接包车,通勤班车,巴士租赁业务 - 鸿鸣巴士 | wika威卡压力表-wika压力变送器-德国wika代理-威卡总代-北京博朗宁科技 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 交流伺服电机|直流伺服|伺服驱动器|伺服电机-深圳市华科星电气有限公司 | 考勤系统_考勤管理系统_网络考勤软件_政企|集团|工厂复杂考勤工时统计排班管理系统_天时考勤 | 储气罐,真空罐,缓冲罐,隔膜气压罐厂家批发价格,空压机储气罐规格型号-上海申容压力容器集团有限公司 | 全自动固相萃取仪_高通量真空平行浓缩仪-勤业永为 | 酶联免疫分析仪-多管旋涡混合仪|混合器-莱普特科学仪器(北京)有限公司 | 空气弹簧|橡胶气囊|橡胶空气弹簧-上海松夏减震器有限公司 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | 液压扳手-高品质液压扳手供应商 - 液压扳手, 液压扳手供应商, 德国进口液压拉马 | 淘趣英语网 - 在线英语学习,零基础英语学习网站 | 订做不锈钢_不锈钢定做加工厂_不锈钢非标定制-重庆侨峰金属加工厂 | 菲希尔FISCHER测厚仪-铁素体检测仪-上海吉馨实业发展有限公司 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 塑料熔指仪-塑料熔融指数仪-熔体流动速率试验机-广东宏拓仪器科技有限公司 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 集装箱箱号识别_自重载重图像识别_铁路车号自动识别_OCR图像识别 | 钢结构-钢结构厂房-钢结构工程[江苏海逵钢构厂] | 武汉高低温试验箱_恒温恒湿试验箱厂家-武汉蓝锐环境科技有限公司 | 冷水机-冰水机-冷冻机-冷风机-本森智能装备(深圳)有限公司 | 聚合氯化铝-碱式氯化铝-聚合硫酸铁-聚氯化铝铁生产厂家多少钱一吨-聚丙烯酰胺价格_河南浩博净水材料有限公司 | 万博士范文网-您身边的范文参考网站Vanbs.com| 广州二手电缆线回收,旧电缆回收,广州铜线回收-广东益福电缆线回收公司 | 瓶盖扭矩仪(扭力值检测)-百科 | 九州网址_专注于提供网址大全分享推广中文网站导航服务 | 合肥废气治理设备_安徽除尘设备_工业废气处理设备厂家-盈凯环保 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 德国GMN轴承,GMN角接触球轴承,GMN单向轴承,GMN油封,GMN非接触式密封 | 金属雕花板_厂家直销_价格低-山东慧诚建筑材料有限公司 | 蚂蚁分类信息系统 - PHP同城分类信息系统 - MayiCMS | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | 对夹式止回阀_对夹式蝶形止回阀_对夹式软密封止回阀_超薄型止回阀_不锈钢底阀-温州上炬阀门科技有限公司 | 【甲方装饰】合肥工装公司-合肥装修设计公司,专业从事安徽办公室、店面、售楼部、餐饮店、厂房装修设计服务 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 | 「银杏树」银杏树行情价格_银杏树种植_山东程锦园林 | 瑞典Blueair空气净化器租赁服务中心-专注新装修办公室除醛去异味服务! | 大立教育官网-一级建造师培训-二级建造师培训-造价工程师-安全工程师-监理工程师考试培训 | 气弹簧定制-气动杆-可控气弹簧-不锈钢阻尼器-工业气弹簧-可调节气弹簧厂家-常州巨腾气弹簧供应商 | 杭州门窗厂家_阳光房_包阳台安装电话-杭州窗猫铝合金门窗 | 体检车_移动CT车_CT检查车_CT车_深圳市艾克瑞电气有限公司移动CT体检车厂家-深圳市艾克瑞电气有限公司 |