Android 移动应用开发模拟题

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的方式展示手机的信息
图片如下
Android 移动应用开发模拟题_第1张图片
Android 移动应用开发模拟题_第2张图片
Android 移动应用开发模拟题_第3张图片

手机信息如下

品牌 名字 价格 图片
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的运行结果和下图类似
Android 移动应用开发模拟题_第4张图片
建议用时:30分钟

题目5: SQLite数据库操作

见这篇文章的 5-1至5-3
Android编程 期末复习 刷题篇(案例+注意点)

如果能把5-3 从头到尾敲一遍考试就基本上没问题了

参考代码

题目1

Android 移动应用开发模拟题_第5张图片

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();
            }
        });
    }
}


<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
Android 移动应用开发模拟题_第6张图片

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) {
     

            }
        });
    }
}


<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 *
Android 移动应用开发模拟题_第7张图片

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();
            }
        });
    }
}


<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
Android 移动应用开发模拟题_第8张图片

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;
    }
}


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

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

你可能感兴趣的:(#,Android移动应用,学校学习,android,studio,app)