2023TYUT移动应用软件开发程序设计和填空

news2024/10/7 8:24:03

目录

程序设计

程序设计1:根据要求设计UI,补充相应布局文件,即.xml文件

程序设计2:根据要求,补充Activity.java文件

程序填空

说明:


程序设计

程序设计1:根据要求设计UI,补充相应布局文件,即.xml文件

Design the UI using proper layouts and widgets for the House Selling App/Car Selling App. The UI should include multiple widgets such as TextView文本框, EditText输入框, Button按钮,  Radiobutton单选按钮, Checkbox复选框, Menu菜单,Spinner列表,ListView列表,Seekbar进度条,preference设置。

说明:我将4个实验中要求组件整合到一起来设计了UI

UI设计图如下:

(Spinner列表,写代码时我漏掉了,在这就不补充了,)

main_activity.xml文件如下

<?xml version="1.0" encoding="utf-8"?>
<!--布局方式有6种,常用的有LinearLayout、TableLayout、RelativeLayout,此xml以LinearLayout布局编写-->
<!--eg:构建一个2行3列的TableLayout
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android">
    android:layout_width=...
    ...
    <TableRow>
        <组件1.1/>
        <组件1.2/>
        <组件1.3/>
    </TableRow>
    <TableRow>
        <组件2.1/>
        <组件2.2/>
        <组件2.3/>
    </TableRow>
</TableLayout>      
-->
<LinearLayout xmlns:android="...">
    android:id="@+id/llt_02"
    android:layout_width="match_parint"
    android:layout_heigth="wrap_parint"
    android:orientation="vertical">
<!--设置布局的宽为match_parint/wrap_content/具体值-->
<!--设置布局的高为match_parint/wrap_content/具体值-->
<!--orientation设置布局的方向为vertical/horizontal-->
    <TextView
        android:id="@+id/tvCarSale"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:gravity="center"
        android:text="汽车销售"/>
<!--TextView还有textColor,textStyle,textSize,background等属性-->
<!--TextView宽高赋值不同,会影响布局,具体问题,具体分析-->
<!--gravity设置对齐方式left/center/right默认left-->
    <TextView
        android:id="@+id/tvSearch"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text="请输入你想要搜索的汽车:"/>
    <EditText
        android:id="@+id/et1"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:ems="10"
        android:hint="输入关键字"/>
<!--ems设置下划线长度,hint设置未输入时下划线显示的字符-->
    <Button
        android:id="@+id/btmakesure"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text="确认"/>
    <TextView
        android:id="@+id/tvdanxuan"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text="变速箱类型(单选):"/>
    <RadioGroup
        android:id="@+id/rgp1"
        android:layout_width="match_parint"
        android:layout_heigth="wrap_parint"
        android:orientation="horizontal">
<!--设置选项方向为水平-->
        <RadioButton
            android:id="@+id/rbt1"
            android:layout_width="wrap_parint"
            android:layout_heigth="wrap_parint"
            android:text="手动"/>
        <RadioButton
            android:id="@+id/rbt2"
            android:layout_width="wrap_parint"
            android:layout_heigth="wrap_parint"
            android:text="自动"/>
    </RadioGroup>
    <TextView
        android:id="@+id/tvduoxuan"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text=":汽车类型(多选):"/>
    <CheckBox 
        android:id="@+id/ckbSuv"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text=":SUV"/>   
    <CheckBox 
        android:id="@+id/ckbSportsCar"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text=":跑车"/>     
    <CheckBox 
        android:id="@+id/ckbSaloonCar"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text=":轿车"/>   
    <CheckBox 
        android:id="@+id/ckbother"
        android:layout_width="wrap_parint"
        android:layout_heigth="wrap_parint"
        android:text=":其他"/>  
    <FrameLayout
        android:id="@+id/settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_parent"/>
</LinearLayout>

<LinearLayout xmlns:android="..."><!--编写listView布局,并为其添加进度条-->
    android:id="@+id/llt_02"
    android:layout_width="match_parint"
    android:layout_heigth="wrap_parint"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tvCarlistview"
        android:layout_width="match_parint"
        android:layout_heigth="wrap_parint"
        android:text="畅销汽车列表(ListView):"/>
    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parint"
        android:layout_heigth="wrap_parint">
    </ListView>
    <SeekBar
        android:id="@+id/sk"
        android:layout_width="match_parint"
        android:layout_heigth="wrap_parint"
        android:max="100"
        android:progress="50"/>
    <!--max最大进度,progress当前进度-->
</LinearLayout>

meun.xml文件如下

<?xml version="1.0" encoding="utf-8"?>
<!--menu文件写在另一个xml文件中,在Activity中通过重写onCreateOptionsMenu方法,进行调用-->
<menu xmlns:android="...">
    android:layout_width="match_parint"
    android:layout_heigth="match_parint">
    <item
        android:id="@+id/m1"
        android:title="收藏"/>
    <item
        android:id="@+id/m2"
        android:title="历史记录"/>
    <item
        android:id="@+id/m3"
        android:title="帮助与反馈"/>
    <item
        android:id="@+id/m4"
        android:title="关于App"/>
</menu>

listView.item.xml文件如下

<?xml version="1.0" encoding="utf-8"?>
<!--listView的item文件写在另一个xml文件中,通过Adapter与Activity建立联系-->
<LinearLayout xmlns:android="...">
    android:layout_width="match_parint"
    android:layout_heigth="match_parint"
    <TextView
        android:id="@+id/tv_car1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="五菱" />
    <TextView
        android:id="@+id/tv_car2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="大众" />
    <TextView
        android:id="@+id/tv_car3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="比亚迪" />    
    <TextView
        android:id="@+id/tv_car4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="特斯拉" />
</LinearLayout>

setting.xml文件如下

<?xml version="l.0" encoding="utf-8"?>
<PreferenceScreen>
    <Preference
        android:key="largeSize"
        android:title="大字体"
        android:summary="Setting a large font"/>
    <Preference
        android:key="middleSize"
        android:title="中字体"
        android:summary="Setting a middle font"/>
    <Preference
        android:key="smallSize"
        android:title="小字体"
        android:summary="Setting a small font"/>
<!--summary将在title以小字体解释说明title-->
    <Preference
        android:key="cancel"
        android:title="取消"/>
</PreferenceScreen>

程序设计2:根据要求,补充Activity.java文件

1、在Activity中获取RadioButton,为RadioGroup添加监听器,实现OnCheckedChangedListener接口,代码如下


public class MainActivity extends Activity {//继承父类

    private RadioButton shoudong,zidong;//
    private RadioGroup  speedchange
    @Override
    protected void onCreate(Bundle savedInstanceState){//实现onCreate方法,包含下一行
        super.onCreate(savedlnstanceState);
        setContentView(R.layout.activity_main);//调用方法,展现视图View

        speedchange=(RadioGroup)findViewByld(R.id.bgp1);
        shoudong=(RadioButton)findViewByld(R.id.rbt1);
        zidong=(RadioButton)findViewByld(R.id.rbt2);//这里的bgp1,rbt1,rbt2与xml文件中id一致

        speedchange.setOnClickedChangeListener(new zjrRadioButtonListener());
    }
    class zjrRadioButtonListener implements OnClickedChangeListener{
        @Override
        public void onCheckedChanged(RadioGroup Group,int checkedId){
            switch(checkedId){
                case R.id.rbt1:
                Log.i("speedchange","变速箱选择了"+rbt1.getText().toString());
                break;
                case R.id.rbt2:
                Log.i("speedchange","变速箱选择了"+rbt2.getText().toString());
                break; 
//这里点击事件发生后我写了log,考试时要具体分析 
            }
        }
    }
}

2、在Activity中获取Button,添加监听器,实现OnClickListener接口,并利用Intent实现两个活动状态之间的转换,代码如下


public class MainActivity extends Activity {//继承父类

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState){//实现onCreate方法,包含下一行
        super.onCreate(savedlnstanceState);
        setContentView(R.layout.activity_main);//调用方法,展现视图View

        button=(Button)findViewByld(R.id.btmakesure);
        button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent=new Intent(MainActivity.this,NextActivity.class);
                startActivity(intent);
            }
        });
    }
}

3、编写Menu菜单的Activity.java文件

//The Activity.java for menu
public class TipCalculatorActivity extends Activity{
 
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedlnstanceState);
        setContentView(R.layout.activity_main);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {//The code that displays the menu展示菜单
        getMenuInflater().inflate(R.menu-activity_tip_calculator, menu);
        return true;  
    }
    @Override
    public boolean onOptionsItemSelected(Menultem item) {//The code that handles the menu item events处理项目点击事件
        switch(item.getItemId()) {
            case R.id.menu_settings:
               startActivity(new Intent(getApplicationContext( ),SettingsActivity.class));
                return true;
            case R.id.menu_about:
                startActivity(new Intent(getApplicationContext( ),AboutActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

程序填空

        程序填空能考的实在太多了,上面的程序设计题中已经覆盖了很多填空的知识,所以要理解地选择记忆

补充一些上面没有涉及到的,如下:

1、第四章how to trace code execution跟踪代码执行的两种方法

  • 利用日志Logcat
//How to use the Log class如何使用日志
//第1步:Import the Log class导入日志类
import android.util.Log;

//第2步:Declare a constant for the tag parameter为标签参数声明一个常量
private static final String TAG = "TipCalculatorActivity";

//第3步:Send messages to the log向日志发送消息
Log.d(TAG, "calculateAndDisplay method started");
Log.d(TAG, "billAmount: " + billAmount);
  • 利用消息提示框Toast
//How to display a toast如何展示消息框
//第1步:Import the Toast class导入消息类
import android.widget.Toast;

//第2步:Use two statements使用方法makeText()和show()
Toast t = Toast.makeText(this, "onCreate method", Toast.LENGTH_SHORT);
t.show();

//第3步:Use a single statement (method chaining)使用方法makeText()链接
Toast.makeText(this, "onCreate method ", Toast.LENGTH_SHORT).show();

2、第十章

  • 考点一:how to use SAX ( Simple API for XML) to parse  XML files
final String FILENAME = "news_feed.xml";
RSSFeed feed;
try {
  
    SAXParserFactory factory = SAXParserFactory.newlnstance();// get the XML reader
    SAXParser parser = factory.newSAXParser();
    XMLReader xmlreader = parser.getXMLReader();
  
    RSSFeedHandler theRssHandler = new RSSFeedHandler();// set content handler
    xmlreader.setContentHandler(theRssHandler);
  
    FilelnputStream in = openFilelnput(FILENAME); // get the input stream
  
    InputSource is = new InputSource(in);// parse the data
    xmlreader.parse(is);

    feed = theRssHandler.getFeed();// get the content handler and return it
}
catch (Exception e) {
    Log.e("News reader", e.toString());
}
  • 考点二:How to use an adapter to display data in a list view
//Code that creates and sets the adapter创建和设置适配器的代码

ArrayList <RSSItem> items = feed.getAllItems();// 获取提要项

ArrayList <HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();// 创建Map<String, ?>对象列表
for (RSSItem item : items) {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("date", item.getPubDateFormatted());
    map.put("title", item.getTitle( ));
    data.add(map);
}

int resource = R.layout.listview_item;// 创建资源变量、from变量和to变量
String[] from = {"date", "title"};
int[] to = {R.id.pubDateTextView, R.id.titleTextView};

SimpleAdapter adapter =new SimpleAdapter(this, data, resource, from, to);// 创建和设置适配器
itemsListView.setAdapter(adapter);

3、第十一章

  • 考点一:Service核心代码
//The NewsReaderService class with its lifecycle methods implemented
//NewsReaderService类及其实现的生命周期方法
public class NewsReaderService extends Service {
    @Override
    public void onCreate() {    
    }
    @Override
    public int onStartCommand(Intent intent, int flags, int startld) {
        return START_STICKY;
    }
    @Override
    public IBinder onBind(Intent intent) {   
        return null;
    }
    @Override
    public void onDestroyO {
    }
}
  • 考点二:notifications核心代码
//How to create a notification如何创建通知
//Step 1: Create the variables for the notification步骤1:为通知创建变量
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Updated news feed is available";
CharSequence contentTitle = getText(R.string.app_name);
CharSequence contentText = "Select to view updated feed.";

//Step 2: Create the Notification object步骤2:创建Notification对象
Notification notification =new Notification.Builder(this)
    .setSmallIcon(icon)
    .setTicker(tickerText )
    .setContentTitle(contentTitle)
    .setContentText(contentText )
    .setContentlntent(pendingIntent )
    .setAutoCancel(true)
    .build();

4、第十二章

  • The BootReceiver class
public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("News reader", "Boot completed");

        // start service
        Intent service = new Intent(context, NewsReaderService.class);
        context.startService(service);
    }
}

说明:

        我不推荐大家看我的博文来复习

  • 第一,这篇总结我并没有写完整,至少还剩1/3没写,但是我没时间写了
  • 第二,我总结的只是老师划的重点以及我阅读代码后的见解,能覆盖多少咱说不准
  •  我写的并不是很通俗易懂,实在没时间写那么细,如果看不懂,我建议先去图书馆找android中文书,走马观花地过一遍,我看的是以下两本,图书馆3楼东,关于android开发的书很多

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/416059.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【C++初阶】第十篇:list模拟实现

文章目录一、list的模拟实现三个类及其成员函数接口总览结点类的模拟实现迭代器类的模拟实现迭代器类的模板参数说明迭代器operator->的重载迭代器模拟实现代码list的模拟实现无参构造函数带参构造拷贝构造函数赋值运算符重载函数析构函数begin和endinserteraselist的迭代器…

WordPress添加阿里云OSS对象云储存配置教程

背景&#xff1a;随着页面文章增多&#xff0c;内置图片存储拖连网站响应速度&#xff0c;这里对我来说主要是想提升速度 目的&#xff1a;使用第三方云存储作为图片外存储(图床)&#xff0c;这样处理可以为服务器节省很多磁盘空间&#xff0c;在网站搬家的时候减少文件迁移的工…

【数据结构】堆(笔记总结)

&#x1f466;个人主页&#xff1a;Weraphael ✍&#x1f3fb;作者简介&#xff1a;目前学习C和算法 ✈️专栏&#xff1a;数据结构 &#x1f40b; 希望大家多多支持&#xff0c;咱一起进步&#xff01;&#x1f601; 如果文章对你有帮助的话 欢迎 评论&#x1f4ac; 点赞&…

MySQL--数据库基础--0406

目录 1.什么是数据库&#xff1f; 2. 基本使用 2.1 连接服务器 2.2 数据库的操作在Linux中的体现 2.3 使用案例 3.服务器&#xff0c;数据库&#xff0c;表关系 4.数据逻辑存储 5.SQL的分类 6.存储引擎 1.什么是数据库&#xff1f; 数据库和文件 文件或者数据库&…

OK-MX93开发板-实现Web页面无线点灯

上篇文章&#xff1a;i.MX9352——介绍一款多核异构开发板&#xff0c;介绍了OK-MX9352开发板的基础硬件功能。 本篇来使用OK-MX9352开发板&#xff0c;通过Web界面进行点灯测试&#xff0c;最终的效果如下&#xff1a; 在进行代码编写之前&#xff0c;先在Ubuntu虚拟机上把这…

对比损失Contrastive Loss(CVPR 2006)原理解析

paper&#xff1a;http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf 本文提出的对比损失contrastive loss被广泛应用于自监督模型中&#xff0c;但最初对比损失是作为一个特征降维方法而提出的。 摘要 降维是学习一种映射关系&#xff0c;通过这种映射关…

day10 线程池及gdb调试多线程

目录 线程池的概念 概念&#xff1a; 必要性&#xff1a; 线程池的基本结构&#xff1a; 线程池的实现 完整代码 线程的GDB调试 线程池的概念 概念&#xff1a; 通俗的讲就是一个线程的池子&#xff0c;可以循环的完成任务的一组线程集合&#xff1b; 必要性&#xff…

【软件工程】为什么要选择软件工程专业?

个人主页&#xff1a;【&#x1f60a;个人主页】 文章目录前言软件工程&#x1f4bb;&#x1f4bb;&#x1f4bb;就业岗位&#x1f468;‍&#x1f4bb;&#x1f468;‍&#x1f4bb;&#x1f468;‍&#x1f4bb;就业前景&#x1f6e9;️&#x1f6e9;️&#x1f6e9;️工作环…

趣谈之什么是 API 货币化?

本文介绍了 API 货币化和 APISIX 实现 API 货币化方法。 作者刘维&#xff0c;API7.ai 技术工程师&#xff0c;Apache APISIX Contributor 原文链接 什么是 API 货币化 想象你开发并部署了一个服务&#xff0c;能够搜集你所在城市所有超市的打折和优惠信息&#xff0c;其他的…

C生万物 | 校招热门考点 —— 结构体内存对齐

文章目录一、前言结构体偏移量计算&#xff1a;offsetof二、规则介绍例题的分解与细说三、习题演练1、练习①2、练习②四、为什么存在内存对齐?1、平台原因(移植原因)2、性能原因五、如何修改默认对齐数六、实战演练✍一道百度笔试题&#xff1a; offsetof 宏的实现&#x1f4…

深度学习基础篇之深度神经网络(DNN)

神经网络不应该看做是一个算法&#xff0c;应该看做是一个特征挖掘方法。在实际的业界发展过程中&#xff0c;数据的作用往往大于模型&#xff0c;当我们把数据的隐藏特征提取出来之后&#xff0c;用很简单的模型也能预测的很好。 神经网络模型由生物神经中得到启发。在生物神…

【Linux】Makefile的简述

目录 前言&#xff1a; 一、Makefile的规则 二、Makefile的函数语法 &#xff08;1&#xff09;通配符pattern ​&#xff08;2&#xff09; 删除clean ​&#xff08;3&#xff09; 立即变量、延时变量 &#xff08;4&#xff09; Makefile常用函数 3-1.Makefile要达到…

第11章_常用类和基础API

第11章_常用类和基础API 讲师&#xff1a;尚硅谷-宋红康&#xff08;江湖人称&#xff1a;康师傅&#xff09; 官网&#xff1a;http://www.atguigu.com 本章专题与脉络 1. 字符串相关类之不可变字符序列&#xff1a;String 1.1 String的特性 java.lang.String 类代表字符串…

vue之--使用TypeScript

搭配 TypeScript 使用 Vue​ 像 TypeScript 这样的类型系统可以在编译时通过静态分析检测出很多常见错误。这减少了生产环境中的运行时错误&#xff0c;也让我们在重构大型项目的时候更有信心。通过 IDE 中基于类型的自动补全&#xff0c;TypeScript 还改善了开发体验和效率。…

2023年美赛春季赛 Y题详细思路

由于今年各种各样的原因&#xff0c;导致美赛头一次&#xff0c;据说也将是最后一次&#xff0c;临时调整&#xff0c;加设春季赛。这对于急需建模奖项的大家来说是一个很好的机会。无论怎样的原因&#xff0c;今年美赛我们可能有所遗憾。但&#xff0c;春季赛也许就是弥补遗憾…

HTML4.1表单标签

input&#xff08;登录、注册、搜索功能&#xff09; type属性值类型称号展示类型text文本框placeholder占位符password密码框placeholder占位符radio单选框name checked&#xff08;默认选中&#xff09;同类型单选checkbox复选框 checked file 文件选择multiple多文件选择s…

分类预测 | MATLAB实现CNN-GRU-Attention多输入分类预测

分类预测 | MATLAB实现CNN-GRU-Attention多输入分类预测 目录分类预测 | MATLAB实现CNN-GRU-Attention多输入分类预测分类效果模型描述程序设计参考资料分类效果 模型描述 Matlab实现CNN-GRU-Attention多变量分类预测 1.data为数据集&#xff0c;格式为excel&#xff0c;12个输…

集合-LinkedList

LinkedList LinkedList的概述 LinkedList的底层使用双向链表实现。 链表是一种线性数据结构&#xff0c;其中每个元素都是一个单独的对象&#xff0c;包含一个指向列表中下一个节点的引用。 它可以用于实现各种抽象数据类型&#xff0c;例如列表、堆栈、队列等。 LinkedLis…

安装Nginx——docker安装

使用docker安装Nginx 1.开启docker systemctl start docker docker search nginx[rootlocalhost ~]# systemctl start docker //开启docker [rootlocalhost ~]# docker search nginx //搜素镜像 2. docker pull nginxdocker imagesdocker run -…

如何将录音转成文字?

在现代社会中&#xff0c;随着语音技术的不断发展和普及&#xff0c;将录音转换为文字变得越来越容易。无论是为了记录会议、面试、讲座、采访&#xff0c;还是为了记录个人的思考和想法&#xff0c;将录音转换为文字是一种方便快捷的方式。本文将介绍几种将录音转换为文字的方…