Android 移動應用開發模擬題
題目
本套題難度偏低,可以作為考前熱身題
注: 建議時間包括了(創建專案,加上打開虛擬機的卡頓時間,完成專案的錄屏時間,提交代碼的時間,出現問題找bug的時間)
注 :關于多執行緒的題目還是傾向于考定時器這種稍微有點難度的
鏈接如下
安卓編程 多執行緒與Handler訊息傳遞(附案例 計時器)
參考代碼和結果展示放在文末
題目1:
撰寫APP
第一個UI 為一個TextView, 展示你的學號和姓名
第二個UI 為一個Button, 初始的Text 為"0" ,當用戶點擊它的時候,Button的Text會相應的變成"1",“2”,“3” ,Button上的text代表了Button被點擊的次數
建議用時: 10分鐘
題目2:
撰寫APP
第一個UI 為一個TextView, 展示你的學號和姓名
第二個UI 為一個TextView, 展示Spinner中選擇的資訊
第二個UI 為一個Spinner 它有三個值 “彩券”,“把你揉碎捏成蘋果”,“遲遲”,當用戶select到Spinner中相應歌曲的名字時,第二個TextView會展示被select到的歌曲名
建議用時: 10分鐘
題目3:
撰寫APP
第一個UI 為一個TextView, 展示你的學號和姓名
第二個UI 為一個Button 當用戶點擊id時候, 會跳出一個AlertDialog
- 它的標題顯示你的名字,它的資訊顯示你所在的城市,AlertDialog有兩個按鈕
- Positive Buuton 名為"Red" ,當點擊它時,對話框消失并且TextView的顏色變為紅色
- Negative Button 名為"Black" 當點擊它時,對話框消失并且TextView的顏色變為黑色
建議用時: 10分鐘
題目4:
撰寫APP
第一個UI 為一個TextView, 展示你的學號和姓名
第二個UI 為一個ListView 通過自定義Adapter的方式展示手機的資訊
圖片如下



手機資訊如下
| 品牌 | 名字 | 價格 | 圖片 |
|---|---|---|---|
| Apple | Apple iPhone XR Fully Unlocked,64 GB | S629.00 | iphone_xr_o.jpg |
| Huawei | Huawei P30 Pro s899.99 256GB+8GB RAM | s899.99 | p30pro.jpg |
| Samsung | Samsung Galaxy S10 Factory Unlocked Phone with 128GB | s899.99 | s10plus.jpg |
其中品牌的字體顏色為 黑色(#000)
名字的字體顏色為默認
價格的字體顏色為藍色(#00f)
ImgView的大小和寬度是120dp
APP的運行結果和下圖類似

建議用時:30分鐘
題目5: SQLite資料庫操作
見這篇文章的 5-1至5-3
Android編程 期末復習 刷題篇(案例+注意點)
如果能把5-3 從頭到尾敲一遍考試就基本上沒問題了
參考代碼
題目1

1.普通解法
耗時: 5:24.27
package com.example.tty_task1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button btn;
TextView tv;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
tv = findViewById(R.id.tv);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btn.setText(String.valueOf(++count));
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="名字: Joker-Tong 學號: Weary_PJ" />
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0" />
</LinearLayout>
2.多執行緒解法
耗時: 6:20.44
package com.example.tty_task1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button btn;
TextView tv;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button);
tv = findViewById(R.id.textView);
final Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
if (msg.what == 666) {
btn.setText(String.valueOf(++count));
}
return false;
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
Message message = new Message();
message.what = 666;
handler.sendMessage(message);
}
}).start();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="名字: Joker-Tong 學號: Weary_PJ" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0" />
</LinearLayout>
題目2
耗時: 6:30.72

package com.example.tty_task2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tv;
Spinner spinner;
String musics[] = new String[]{"彩券", "把你揉碎捏成蘋果", "遲遲"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
spinner = findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, musics);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
tv.setText(musics[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="名字: Joker-Tong 學號: Weary_PJ" />
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="薛之謙" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
題目3
*耗時: 7:50.24 *

package com.example.tty_task3;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button btn;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
tv = findViewById(R.id.tv);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder bl = new AlertDialog.Builder(MainActivity.this);
bl.setTitle("Joker-Tong").setMessage("溫州").setPositiveButton("Red", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tv.setTextColor(Color.RED);
}
}).setNegativeButton("Black", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tv.setTextColor(Color.BLACK);
}
}).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="名字: Joker-Tong 學號: Weary_PJ" />
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="顯示對話框" />
</LinearLayout>
題目4
耗時: 20:45.96

package com.example.tty_task4;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ListView lv;
ArrayList<Phone> list;
PhoneAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = findViewById(R.id.lv);
list = new ArrayList<>();
list.add(new Phone(R.drawable.applr, "Apple", "Apple iPhone XR Fully Unlocked,64 GB", "S629.00"));
list.add(new Phone(R.drawable.huawei, "Huawei", "Huawei P30 Pro s899.99 256GB+8GB RAM", "S899.99"));
list.add(new Phone(R.drawable.samsung, "Samsung", "Samsung Galaxy S10 Factory Unlocked Phone with 128GB", "S899.99"));
adapter = new PhoneAdapter(this, list);
lv.setAdapter(adapter);
}
}
package com.example.tty_task4;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
public class PhoneAdapter extends ArrayAdapter<Phone> {
private Context context;
private ArrayList<Phone> list;
public PhoneAdapter(@NonNull Context context, ArrayList<Phone> list) {
super(context, android.R.layout.simple_list_item_1, list);
this.context = context;
this.list = list;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.row, null, false);
TextView grand = view.findViewById(R.id.row_grand);
TextView name = view.findViewById(R.id.row_name);
TextView price = view.findViewById(R.id.row_price);
ImageView img = view.findViewById(R.id.row_img);
Phone phone = list.get(position);
grand.setText(phone.getBrand());
name.setText(phone.getName());
price.setText(phone.getPrice());
img.setImageResource(phone.getPicId());
return view;
}
}
package com.example.tty_task4;
public class Phone {
private int picId;
private String brand;
private String name;
private String price;
public int getPicId() {
return picId;
}
public void setPicId(int picId) {
this.picId = picId;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public Phone(int picId, String brand, String name, String price) {
this.picId = picId;
this.brand = brand;
this.name = name;
this.price = price;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<ImageView
android:id="@+id/row_img"
android:layout_width="120dp"
android:layout_height="120dp"
app:srcCompat="@drawable/applr" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="15dp">
<TextView
android:id="@+id/row_grand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="17sp"
android:text="TextView" />
<TextView
android:id="@+id/row_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/row_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#00f"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="名字: Joker-Tong 學號: Weary_PJ" />
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/249097.html
標籤:其他
