日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

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

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

瀏覽:26日期: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
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲精品1区2区| 国产一区二区高清| 日韩国产一区| 亚洲精品国模| 中文字幕一区二区三区日韩精品 | 先锋影音久久久| 国产超碰精品| 激情国产在线| а√天堂中文在线资源8| 国产福利91精品一区二区| 91大神在线观看线路一区| 最新亚洲国产| 亚洲aa在线| 日韩不卡在线观看日韩不卡视频| 日韩免费看片| 欧美 日韩 国产精品免费观看| 岛国精品一区| 天堂中文在线播放| 国产精品毛片一区二区在线看| 久久99国产精品视频| 色婷婷色综合| 亚洲一区二区三区高清| 日韩精品视频在线看| 国产精品午夜一区二区三区| 国产suv精品一区二区四区视频| 日韩国产一区二区三区| 日韩中文影院| 米奇777超碰欧美日韩亚洲| 在线亚洲免费| 男女性色大片免费观看一区二区| 亚洲精品中文字幕99999| 精品色999| 美女精品在线| 久久精品国产免费| 尤物在线精品| 国产亚洲字幕| 久久婷婷一区| 日本不卡中文字幕| 伊人久久av| 婷婷亚洲精品| 成人福利视频| 蜜桃传媒麻豆第一区在线观看| 日韩激情一二三区| 91精品国产自产在线观看永久∴| 91久久久精品国产| 日韩精品一级| 亚洲午夜精品久久久久久app| 日韩高清国产一区在线| 欧美日韩在线二区| 欧美精品二区| 亚洲尤物在线| 都市激情国产精品| 日韩国产高清在线| 亚洲女人av| 日韩欧美不卡| 国产麻豆一区| 亚洲欧美日韩国产一区二区| 国产在线欧美| 免费观看在线色综合| 在线综合欧美| 日本91福利区| а√天堂8资源中文在线| 免费毛片在线不卡| 午夜亚洲福利| 欧美aa在线视频| 日韩成人综合| 香蕉国产精品| 亚洲综合专区| 日本在线高清| 老牛影视一区二区三区| 国产另类在线| 亚洲一级特黄| 蜜桃视频在线观看一区| 欧美高清不卡| 国内精品福利| 日本不卡免费高清视频在线| 精品高清久久| 国产不卡精品| 欧美日韩视频免费观看| 日韩一区三区| 激情五月综合网| 黄色日韩在线| 中文字幕日本一区| 日本成人精品| 国产精品白丝一区二区三区| 欧美另类中文字幕| 美女精品久久| 精品日韩视频| 爽爽淫人综合网网站| 在线视频精品| 免费观看在线综合| 国产精品一区二区三区四区在线观看 | 国产精品videossex久久发布 | 婷婷精品视频| 日韩在线一区二区| 欧美伊人久久| 日韩一区自拍| 亚洲一区国产| 久久久精品国产**网站| 久久精品亚洲人成影院| 欧美日韩国产在线观看网站 | 日本成人在线不卡视频| 久久99影视| 欧美日韩精品一区二区视频| 蜜臀va亚洲va欧美va天堂| 欧美一区91| 日本久久成人网| 国产日韩视频| 精品72久久久久中文字幕| 亚洲在线免费| 激情久久久久久久| 一本大道色婷婷在线| 国产激情一区| 蜜臀av国产精品久久久久 | 鲁大师影院一区二区三区| 91嫩草亚洲精品| 久久99久久人婷婷精品综合| 日韩av资源网| 亚洲久久视频| 中文字幕av亚洲精品一部二部| 国精品一区二区三区| 国产尤物精品| 一本一道久久a久久精品蜜桃| 亚洲精品国产嫩草在线观看 | 国产精品一区二区精品视频观看 | 蜜臀久久久久久久| 国产偷自视频区视频一区二区| 三级精品视频| 女人天堂亚洲aⅴ在线观看| 久久久久久美女精品| 韩国精品主播一区二区在线观看| 麻豆国产精品一区二区三区| 欧美久久一区二区三区| 欧美伊人久久| 2023国产精品久久久精品双| 波多视频一区| 免费美女久久99| 青草久久视频| 天堂av在线一区| 日韩成人三级| 天堂va欧美ⅴa亚洲va一国产| 欧美激情aⅴ一区二区三区 | 视频一区视频二区中文字幕| 精品三级国产| 日本美女一区| 日韩一二三区在线观看| 精品中文在线| 欧美二区视频| 日韩亚洲国产欧美| 蜜桃国内精品久久久久软件9| 成人欧美一区二区三区的电影| 精品国产欧美| 99视频精品视频高清免费| 久久免费黄色| 国产午夜久久| 亚洲精品高潮| 国产精品白浆| 成年男女免费视频网站不卡| 精品欧美一区二区三区在线观看| 蜜臀av性久久久久蜜臀aⅴ流畅| 国产超碰精品| 国产精品精品| 国产精品99一区二区三| 综合色一区二区| 亚洲精品福利| 国产精品v一区二区三区| 成人羞羞视频在线看网址| 另类av一区二区| 久久国产精品色av免费看| 精品久久影院| 亚洲色诱最新| 国产精品传媒麻豆hd| 91超碰国产精品| 亚洲精品少妇| 国产精品高颜值在线观看| 中国女人久久久| 久久国产精品美女| 美女少妇全过程你懂的久久| 日韩精品乱码av一区二区| 粉嫩av一区二区三区四区五区 | 国产理论在线| 天海翼亚洲一区二区三区| 精品国产不卡一区二区| 日韩专区一卡二卡| 国产一区二区视频在线看| 在线观看视频免费一区二区三区| 国产精品成人3p一区二区三区| 日韩三区在线| 久久精品国产99国产| 日韩三级一区| 亚洲在线免费| 婷婷激情图片久久| 日韩电影在线视频| 福利一区二区三区视频在线观看| 亚洲精品日韩久久| 亚洲一区日韩| 亚洲精品91| 国产综合亚洲精品一区二| 国产精品精品| 日本а中文在线天堂|