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

相关文章

使用jenv工具管理多个JDK版本的方法步骤

《使用jenv工具管理多个JDK版本的方法步骤》jenv是一个开源的Java环境管理工具,旨在帮助开发者在同一台机器上轻松管理和切换多个Java版本,:本文主要介绍使用jenv工具管理多个JD... 目录一、jenv到底是干啥的?二、jenv的核心功能(一)管理多个Java版本(二)支持插件扩展(三)环境隔

Python中bisect_left 函数实现高效插入与有序列表管理

《Python中bisect_left函数实现高效插入与有序列表管理》Python的bisect_left函数通过二分查找高效定位有序列表插入位置,与bisect_right的区别在于处理重复元素时... 目录一、bisect_left 基本介绍1.1 函数定义1.2 核心功能二、bisect_left 与

Spring中管理bean对象的方式(专业级说明)

《Spring中管理bean对象的方式(专业级说明)》在Spring框架中,Bean的管理是核心功能,主要通过IoC(控制反转)容器实现,下面给大家介绍Spring中管理bean对象的方式,感兴趣的朋... 目录1.Bean的声明与注册1.1 基于XML配置1.2 基于注解(主流方式)1.3 基于Java

基于Python+PyQt5打造一个跨平台Emoji表情管理神器

《基于Python+PyQt5打造一个跨平台Emoji表情管理神器》在当今数字化社交时代,Emoji已成为全球通用的视觉语言,本文主要为大家详细介绍了如何使用Python和PyQt5开发一个功能全面的... 目录概述功能特性1. 全量Emoji集合2. 智能搜索系统3. 高效交互设计4. 现代化UI展示效果

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

Mysql中的用户管理实践

《Mysql中的用户管理实践》:本文主要介绍Mysql中的用户管理实践,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录13. 用户管理13.1 用户 13.1.1 用户信息 13.1.2 创建用户 13.1.3 删除用户 13.1.4 修改用户

linux服务之NIS账户管理服务方式

《linux服务之NIS账户管理服务方式》:本文主要介绍linux服务之NIS账户管理服务方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、所需要的软件二、服务器配置1、安装 NIS 服务2、设定 NIS 的域名 (NIS domain name)3、修改主

Python+PyQt5开发一个Windows电脑启动项管理神器

《Python+PyQt5开发一个Windows电脑启动项管理神器》:本文主要介绍如何使用PyQt5开发一款颜值与功能并存的Windows启动项管理工具,不仅能查看/删除现有启动项,还能智能添加新... 目录开篇:为什么我们需要启动项管理工具功能全景图核心技术解析1. Windows注册表操作2. 启动文件

gradle第三方Jar包依赖统一管理方式

《gradle第三方Jar包依赖统一管理方式》:本文主要介绍gradle第三方Jar包依赖统一管理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录背景实现1.顶层模块build.gradle添加依赖管理插件2.顶层模块build.gradle添加所有管理依赖包

基于Python打造一个智能单词管理神器

《基于Python打造一个智能单词管理神器》这篇文章主要为大家详细介绍了如何使用Python打造一个智能单词管理神器,从查询到导出的一站式解决,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 项目概述:为什么需要这个工具2. 环境搭建与快速入门2.1 环境要求2.2 首次运行配置3. 核心功能使用指