八、食堂管理之菜品详细信息界面(可添加评论;ListView)

2023-11-09 08:50

本文主要是介绍八、食堂管理之菜品详细信息界面(可添加评论;ListView),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本界面主要功能:

显示菜品的详细信息及对该菜品的评论

Acitivity:DetailsPage

package com.example.fanpeng.smartcanteen;import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;import org.litepal.LitePal;import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;public class DetailsPage extends AppCompatActivity {private TextView dishName,dishPrice,dishGrade;private Button btn,btn_f5;private ImageView dishImage;private List<Comment> commentList;private String TAG="MyCheck";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_details_page);Intent intent=getIntent();Bundle bundle=intent.getExtras();Dishes dishes=(Dishes)bundle.getSerializable("dishes");User user=(User)bundle.getSerializable("user");Log.d(TAG,dishes.getName());dishName=findViewById(R.id.show_dish_name);dishPrice=findViewById(R.id.show_dish_price);dishGrade=findViewById(R.id.show_dish_grade);dishImage=findViewById(R.id.show_dish_image);btn=findViewById(R.id.add_comment);btn_f5=findViewById(R.id.f5_comment);//dishImage//dishImage.set//图片暂时未设置dishName.setText(dishes.getName());dishPrice.setText(String.valueOf(dishes.getPrice())+"元");double AverGrade= LitePal.where("dishes_id = ?",String.valueOf(dishes.getId())).average(Comment.class,"grade");BigDecimal b=new BigDecimal(AverGrade);AverGrade=b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();dishGrade.setText("评分:"+String.valueOf(AverGrade));dishImage.setImageBitmap(BitmapFactory.decodeFile(dishes.getPicturePath()));//评论列表///commentList= LitePal.where("dishes_id=?",String.valueOf(dishes.getId())).find(Comment.class);//初始化CommentAdapter adapter=new CommentAdapter(DetailsPage.this,R.layout.comment_menu,commentList);ListView listView=findViewById(R.id.comment_list);listView.setAdapter(adapter);//添加评论/btn.setOnClickListener(new addListener(user,dishes));btn_f5.setOnClickListener(new f5Listener(dishes));}public class f5Listener implements  View.OnClickListener{Dishes dishes;public f5Listener(Dishes dishes){this.dishes=dishes;}@Overridepublic void onClick(View v) {commentList= LitePal.where("dishes_id=?",String.valueOf(dishes.getId())).find(Comment.class);//初始化Log.d(TAG,String.valueOf(dishes.getId()));Log.d(TAG,String.valueOf(dishes.getCommentCount()));CommentAdapter adapter=new CommentAdapter(DetailsPage.this,R.layout.comment_menu,commentList);ListView listView=findViewById(R.id.comment_list);listView.setAdapter(adapter);Toast.makeText(DetailsPage.this,"已刷新",Toast.LENGTH_SHORT).show();}}public class addListener implements  View.OnClickListener{User user;Dishes dishes;addListener(User user, Dishes dishes){this.user=user;this.dishes=dishes;}@Overridepublic void onClick(View v) {//触发添加评论事件,记得将评论save,相关的user和dishes的saveIntent intent=new Intent(DetailsPage.this,AddCommentPage.class);Bundle bundle=new Bundle();bundle.putSerializable("dishes1",dishes);bundle.putSerializable("user1",user);Log.d(TAG,dishes.getName()+"1");intent.putExtras(bundle);startActivity(intent);Toast.makeText(DetailsPage.this,"请为此菜品添加评论",Toast.LENGTH_SHORT).show();}}}
 

layout:activity_details_page.xml

<?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"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="#fcfbf4"tools:context=".DetailsPage"><RelativeLayoutandroid:layout_height="wrap_content"android:layout_width="match_parent"android:background="#fcfbf4"android:layout_weight="0"android:layout_marginTop="10dp"><ImageViewandroid:id="@+id/show_dish_image"android:layout_width="200dp"android:layout_height="150dp"android:src="@mipmap/ic_launcher"/><TextViewandroid:id="@+id/show_dish_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@id/show_dish_image"android:layout_alignTop="@id/show_dish_image"android:text="菜名"android:textSize="25sp"/><TextViewandroid:id="@+id/show_dish_price"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@id/show_dish_image"android:layout_below="@id/show_dish_name"android:layout_marginTop="20dp"android:text="售价"android:textSize="25sp"/><TextViewandroid:id="@+id/show_dish_grade"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@id/show_dish_image"android:layout_below="@id/show_dish_price"android:layout_marginTop="20dp"android:text="评分"android:textSize="25sp"/></RelativeLayout><ListViewandroid:id="@+id/comment_list"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"/><Buttonandroid:id="@+id/add_comment"android:text="添   加   评   论"android:layout_height="35dp"android:layout_weight="0"android:layout_width="match_parent"android:background="#beb391"android:layout_gravity="center_horizontal"android:gravity="center"android:textColor="#e3e6c3"android:textSize="18sp" /><Buttonandroid:id="@+id/f5_comment"android:text="刷   新   评   论"android:layout_height="35dp"android:layout_weight="0"android:layout_width="match_parent"android:background="#beb391"android:layout_gravity="center_horizontal"android:gravity="center"android:textColor="#e3e6c3"android:layout_marginTop="5dp"android:textSize="18sp" /></LinearLayout>

注意:

点击添加评论按钮后跳转到评论界面,评论完毕返回本界面后还需要点击刷新评论按钮新添加的评论才会出现。

这篇关于八、食堂管理之菜品详细信息界面(可添加评论;ListView)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/375137

相关文章

在C#中调用Windows防火墙界面的常见方式

《在C#中调用Windows防火墙界面的常见方式》在C#中调用Windows防火墙界面(基础设置或高级安全设置),可以使用进程启动(Process.Start)或Win32API来实现,所以本文给大家... 目录引言1. 直接启动防火墙界面(1) 打开基本防火墙设置(firewall.cpl)(2) 打开高

Elasticsearch 的索引管理与映射配置实战指南

《Elasticsearch的索引管理与映射配置实战指南》在本文中,我们深入探讨了Elasticsearch中索引与映射的基本概念及其重要性,通过详细的操作示例,我们了解了如何创建、更新和删除索引,... 目录一、索引操作(一)创建索引(二)删除索引(三)关闭索引(四)打开索引(五)索引别名二、映射操作(一

Linux创建服务使用systemctl管理详解

《Linux创建服务使用systemctl管理详解》文章指导在Linux中创建systemd服务,设置文件权限为所有者读写、其他只读,重新加载配置,启动服务并检查状态,确保服务正常运行,关键步骤包括权... 目录创建服务 /usr/lib/systemd/system/设置服务文件权限:所有者读写js,其他

在Node.js中使用.env文件管理环境变量的全过程

《在Node.js中使用.env文件管理环境变量的全过程》Node.js应用程序通常依赖于环境变量来管理敏感信息或配置设置,.env文件已经成为一种流行的本地管理这些变量的方法,本文将探讨.env文件... 目录引言为什么使php用 .env 文件 ?如何在 Node.js 中使用 .env 文件最佳实践引

python库pydantic数据验证和设置管理库的用途

《python库pydantic数据验证和设置管理库的用途》pydantic是一个用于数据验证和设置管理的Python库,它主要利用Python类型注解来定义数据模型的结构和验证规则,本文给大家介绍p... 目录主要特点和用途:Field数值验证参数总结pydantic 是一个让你能够 confidentl

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版

Redis实现高效内存管理的示例代码

《Redis实现高效内存管理的示例代码》Redis内存管理是其核心功能之一,为了高效地利用内存,Redis采用了多种技术和策略,如优化的数据结构、内存分配策略、内存回收、数据压缩等,下面就来详细的介绍... 目录1. 内存分配策略jemalloc 的使用2. 数据压缩和编码ziplist示例代码3. 优化的

SpringBoot集成XXL-JOB实现任务管理全流程

《SpringBoot集成XXL-JOB实现任务管理全流程》XXL-JOB是一款轻量级分布式任务调度平台,功能丰富、界面简洁、易于扩展,本文介绍如何通过SpringBoot项目,使用RestTempl... 目录一、前言二、项目结构简述三、Maven 依赖四、Controller 代码详解五、Service

深入解析C++ 中std::map内存管理

《深入解析C++中std::map内存管理》文章详解C++std::map内存管理,指出clear()仅删除元素可能不释放底层内存,建议用swap()与空map交换以彻底释放,针对指针类型需手动de... 目录1️、基本清空std::map2️、使用 swap 彻底释放内存3️、map 中存储指针类型的对象

Linux系统管理与进程任务管理方式

《Linux系统管理与进程任务管理方式》本文系统讲解Linux管理核心技能,涵盖引导流程、服务控制(Systemd与GRUB2)、进程管理(前台/后台运行、工具使用)、计划任务(at/cron)及常用... 目录引言一、linux系统引导过程与服务控制1.1 系统引导的五个关键阶段1.2 GRUB2的进化优