八、食堂管理之菜品详细信息界面(可添加评论;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中使用 ThreadLocal 进行多线程上下文管理及注意事项小结

《SpringBoot中使用ThreadLocal进行多线程上下文管理及注意事项小结》本文详细介绍了ThreadLocal的原理、使用场景和示例代码,并在SpringBoot中使用ThreadLo... 目录前言技术积累1.什么是 ThreadLocal2. ThreadLocal 的原理2.1 线程隔离2

Linux内存泄露的原因排查和解决方案(内存管理方法)

《Linux内存泄露的原因排查和解决方案(内存管理方法)》文章主要介绍了运维团队在Linux处理LB服务内存暴涨、内存报警问题的过程,从发现问题、排查原因到制定解决方案,并从中学习了Linux内存管理... 目录一、问题二、排查过程三、解决方案四、内存管理方法1)linux内存寻址2)Linux分页机制3)

高效管理你的Linux系统: Debian操作系统常用命令指南

《高效管理你的Linux系统:Debian操作系统常用命令指南》在Debian操作系统中,了解和掌握常用命令对于提高工作效率和系统管理至关重要,本文将详细介绍Debian的常用命令,帮助读者更好地使... Debian是一个流行的linux发行版,它以其稳定性、强大的软件包管理和丰富的社区资源而闻名。在使用

Python中的可视化设计与UI界面实现

《Python中的可视化设计与UI界面实现》本文介绍了如何使用Python创建用户界面(UI),包括使用Tkinter、PyQt、Kivy等库进行基本窗口、动态图表和动画效果的实现,通过示例代码,展示... 目录从像素到界面:python带你玩转UI设计示例:使用Tkinter创建一个简单的窗口绘图魔法:用

Python中构建终端应用界面利器Blessed模块的使用

《Python中构建终端应用界面利器Blessed模块的使用》Blessed库作为一个轻量级且功能强大的解决方案,开始在开发者中赢得口碑,今天,我们就一起来探索一下它是如何让终端UI开发变得轻松而高... 目录一、安装与配置:简单、快速、无障碍二、基本功能:从彩色文本到动态交互1. 显示基本内容2. 创建链

SpringBoot使用minio进行文件管理的流程步骤

《SpringBoot使用minio进行文件管理的流程步骤》MinIO是一个高性能的对象存储系统,兼容AmazonS3API,该软件设计用于处理非结构化数据,如图片、视频、日志文件以及备份数据等,本文... 目录一、拉取minio镜像二、创建配置文件和上传文件的目录三、启动容器四、浏览器登录 minio五、

IDEA中的Kafka管理神器详解

《IDEA中的Kafka管理神器详解》这款基于IDEA插件实现的Kafka管理工具,能够在本地IDE环境中直接运行,简化了设置流程,为开发者提供了更加紧密集成、高效且直观的Kafka操作体验... 目录免安装:IDEA中的Kafka管理神器!简介安装必要的插件创建 Kafka 连接第一步:创建连接第二步:选

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

软考系统规划与管理师考试证书含金量高吗?

2024年软考系统规划与管理师考试报名时间节点: 报名时间:2024年上半年软考将于3月中旬陆续开始报名 考试时间:上半年5月25日到28日,下半年11月9日到12日 分数线:所有科目成绩均须达到45分以上(包括45分)方可通过考试 成绩查询:可在“中国计算机技术职业资格网”上查询软考成绩 出成绩时间:预计在11月左右 证书领取时间:一般在考试成绩公布后3~4个月,各地领取时间有所不同

安全管理体系化的智慧油站开源了。

AI视频监控平台简介 AI视频监控平台是一款功能强大且简单易用的实时算法视频监控系统。它的愿景是最底层打通各大芯片厂商相互间的壁垒,省去繁琐重复的适配流程,实现芯片、算法、应用的全流程组合,从而大大减少企业级应用约95%的开发成本。用户只需在界面上进行简单的操作,就可以实现全视频的接入及布控。摄像头管理模块用于多种终端设备、智能设备的接入及管理。平台支持包括摄像头等终端感知设备接入,为整个平台提