1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Android 移动应用开发模拟题

Android 移动应用开发模拟题

时间:2021-05-20 19:18:33

相关推荐

Android 移动应用开发模拟题

Android 移动应用开发模拟题

题目

本套题难度偏低,可以作为考前热身题

注: 建议时间包括了(创建项目,加上打开虚拟机的卡顿时间,完成项目的录屏时间,提交代码的时间,出现问题找bug的时间)

注 :关于多线程的题目还是倾向于考定时器这种稍微有点难度的

链接如下

安卓编程 多线程与Handler消息传递(附案例 计时器)

更多详细的题目可以去下面这篇文章看看

Android编程 移动应用开发 经典习题案例 (附案例 注意点)

参考代码和结果展示放在文末

题目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的方式展示手机的信息

图片如下

手机信息如下

其中品牌的字体颜色为 黑色(#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;@Overrideprotected 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() {@Overridepublic void onClick(View v) {btn.setText(String.valueOf(++count));}});}}

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/tv"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="名字: Joker-Tong 学号: Weary_PJ" /><Buttonandroid: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;@Overrideprotected 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() {@Overridepublic boolean handleMessage(@NonNull Message msg) {if (msg.what == 666) {btn.setText(String.valueOf(++count));}return false;}});btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {new Thread(new Runnable() {@Overridepublic void run() {Message message = new Message();message.what = 666;handler.sendMessage(message);}}).start();}});}}

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="名字: Joker-Tong 学号: Weary_PJ" /><Buttonandroid: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[]{"彩券", "把你揉碎捏成苹果", "迟迟"};@Overrideprotected 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() {@Overridepublic void onItemSelected(AdapterView<?> parent, View view, int position, long id) {tv.setText(musics[position]);}@Overridepublic void onNothingSelected(AdapterView<?> parent) {}});}}

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="名字: Joker-Tong 学号: Weary_PJ" /><TextViewandroid:id="@+id/tv"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="薛之谦" /><Spinnerandroid: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;@Overrideprotected 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() {@Overridepublic void onClick(View v) {AlertDialog.Builder bl = new AlertDialog.Builder(MainActivity.this);bl.setTitle("Joker-Tong").setMessage("温州").setPositiveButton("Red", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {tv.setTextColor(Color.RED);}}).setNegativeButton("Black", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {tv.setTextColor(Color.BLACK);}}).show();}});}}

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/tv"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="名字: Joker-Tong 学号: Weary_PJ" /><Buttonandroid: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;@Overrideprotected 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@Overridepublic 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="/apk/res/android"xmlns:app="/apk/res-auto"android:orientation="horizontal" android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center_vertical"><ImageViewandroid:id="@+id/row_img"android:layout_width="120dp"android:layout_height="120dp"app:srcCompat="@drawable/applr" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:paddingLeft="15dp"><TextViewandroid:id="@+id/row_grand"android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="#000"android:textSize="17sp"android:text="TextView" /><TextViewandroid:id="@+id/row_name"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="TextView" /><TextViewandroid: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="/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="名字: Joker-Tong 学号: Weary_PJ" /><ListViewandroid:id="@+id/lv"android:layout_width="match_parent"android:layout_height="match_parent" /></LinearLayout>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。