八、食堂管理之菜品详细信息界面(可添加评论;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

相关文章

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的进化优

Spring Security 前后端分离场景下的会话并发管理

《SpringSecurity前后端分离场景下的会话并发管理》本文介绍了在前后端分离架构下实现SpringSecurity会话并发管理的问题,传统Web开发中只需简单配置sessionManage... 目录背景分析传统 web 开发中的 sessionManagement 入口ConcurrentSess

Linux之UDP和TCP报头管理方式

《Linux之UDP和TCP报头管理方式》文章系统讲解了传输层协议UDP与TCP的核心区别:UDP无连接、不可靠,适合实时传输(如视频),通过端口号标识应用;TCP有连接、可靠,通过确认应答、序号、窗... 目录一、关于端口号1.1 端口号的理解1.2 端口号范围的划分1.3 认识知名端口号1.4 一个进程

SpringBoot结合Knife4j进行API分组授权管理配置详解

《SpringBoot结合Knife4j进行API分组授权管理配置详解》在现代的微服务架构中,API文档和授权管理是不可或缺的一部分,本文将介绍如何在SpringBoot应用中集成Knife4j,并进... 目录环境准备配置 Swagger配置 Swagger OpenAPI自定义 Swagger UI 底

Linux权限管理与ACL访问控制详解

《Linux权限管理与ACL访问控制详解》Linux权限管理涵盖基本rwx权限(通过chmod设置)、特殊权限(SUID/SGID/StickyBit)及ACL精细授权,由umask决定默认权限,需合... 目录一、基本权限概述1. 基本权限与数字对应关系二、权限管理命令(chmod)1. 字符模式语法2.

在macOS上安装jenv管理JDK版本的详细步骤

《在macOS上安装jenv管理JDK版本的详细步骤》jEnv是一个命令行工具,正如它的官网所宣称的那样,它是来让你忘记怎么配置JAVA_HOME环境变量的神队友,:本文主要介绍在macOS上安装... 目录前言安装 jenv添加 JDK 版本到 jenv切换 JDK 版本总结前言China编程在开发 Java