当前位置: 首页 > news >正文

Android Studio 动态表格显示效果

最终效果

一、先定义明细的样式 table_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="40dp"android:background="@color/white"android:paddingLeft="10dp"android:paddingTop="2dp"android:layout_gravity="left"android:paddingBottom="2dp"><TextViewandroid:id="@+id/tab_row_col0"android:layout_width="350px"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:singleLine="true"android:text="row_col0"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_row_col1"android:layout_width="100px"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/tab_row_col0"android:layout_centerVertical="true"android:singleLine="true"android:text="row_col1"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_row_col2"android:layout_width="100px"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/tab_row_col1"android:layout_centerVertical="true"android:singleLine="true"android:text="row_col2"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_row_col3"android:layout_width="100px"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/tab_row_col2"android:layout_centerVertical="true"android:singleLine="true"android:text="row_col3"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_row_col4"android:layout_width="100px"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/tab_row_col3"android:layout_centerVertical="true"android:singleLine="true"android:text="row_col4"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_row_col5"android:layout_width="100px"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/tab_row_col4"android:layout_centerVertical="true"android:singleLine="true"android:text="row_col5"android:textColor="@color/colorPrimaryDark"android:textSize="18sp"android:visibility="visible" /><!--可以按需求添加应用的最多列,没用到的地方通过代码隐藏--><Buttonandroid:id="@+id/tab_row_btn"android:layout_width="80sp"  android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="20dp"android:background="@android:color/transparent"android:padding="0dp"android:text="编辑"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><!--            android:onClick="btnMinQuantity"--></RelativeLayout>

二、demo页面 activity_show_table.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="fill_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".Meals"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:orientation="horizontal"><!--定义查询条件--><RelativeLayoutandroid:id="@+id/laytitle"android:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="left|top"android:padding="5dp"><EditTextandroid:id="@+id/ed_mealname"android:layout_width="150dp"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:hint="菜品名称"android:text="" /><EditTextandroid:id="@+id/ed_mealpy"android:layout_width="150dp"android:layout_height="wrap_content"android:layout_marginLeft="20dp"android:layout_toRightOf="@id/ed_mealname"android:hint="拼音码"android:text="" /><Buttonandroid:id="@+id/btn_query"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/ed_mealpy"android:text="查询" /><Buttonandroid:id="@+id/btn_downmeal"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_toRightOf="@id/btn_query"android:text="下载菜品" /></RelativeLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="380dp"android:orientation="vertical"><!--显示空数据--><includeandroid:id="@+id/empty_view"layout="@layout/empty_list_item"android:layout_width="match_parent"android:layout_height="match_parent"/><!--表头, 和table_row.xml基本属性相同 --><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/tv_hint_gray"android:paddingLeft="10dp"android:paddingTop="2dp"android:layout_gravity="left"android:paddingBottom="2dp"><!-- 可以根据表头各列的宽度 通过代码控制 显示明细的列的宽度,单位请用px--><TextViewandroid:id="@+id/tab_th_col0"android:layout_width="350px"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:singleLine="true"android:text="菜品名称"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_th_col1"android:layout_width="100px"android:layout_height="wrap_content"android:layout_toRightOf="@id/tab_th_col0"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:singleLine="true"android:text="单价"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_th_col2"android:layout_width="100px"android:layout_height="wrap_content"android:layout_toRightOf="@id/tab_th_col1"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:singleLine="true"android:text="数量"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_th_col3"android:layout_width="100px"android:layout_height="wrap_content"android:layout_toRightOf="@id/tab_th_col2"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:singleLine="true"android:text="th_col3"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_th_col4"android:layout_width="100px"android:layout_height="wrap_content"android:layout_toRightOf="@id/tab_th_col3"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:singleLine="true"android:text="th_col4"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /><TextViewandroid:id="@+id/tab_th_col5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@id/tab_th_col4"android:layout_centerVertical="true"android:layout_marginLeft="10px"android:singleLine="true"android:text="th_col5"android:textColor="@color/colorPrimaryDark"android:textSize="18sp"android:visibility="gone" /><Buttonandroid:id="@+id/tab_th_btn"android:layout_width="80sp"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="20dp"android:background="@android:color/transparent"android:padding="0dp"android:text="编辑"android:textColor="@color/colorPrimaryDark"android:textSize="18sp" /></RelativeLayout><!--显示数据明细--><ListViewandroid:id="@+id/lsv_detail"android:layout_width="match_parent"android:layout_height="380dp" ></ListView></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="90dp"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btn_nextpage"android:layout_width="60dp"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="20dp"android:paddingLeft="5dp"android:paddingRight="5dp"android:text="》" /><Buttonandroid:id="@+id/btn_uppage"android:layout_width="60dp"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_marginRight="10dp"android:layout_toLeftOf="@id/btn_nextpage"android:text="《" /><TextViewandroid:id="@+id/tv_totalinfo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:text="共查询到100条记录,1/5页" /></RelativeLayout></LinearLayout></LinearLayout>

三、ShowTable.java

public class ShowTable extends AppCompatActivity implements View.OnClickListener {EditText ed_mealname;EditText ed_mealpy;Button btn_query;Button btn_downmeal;ListView lsv_detail;Button btn_nextpage;Button btn_uppage;TextView tv_totalinfo;List<dishmeal> mlst=null;MyAdapter<dishmeal> myAdapter=null;private View emptyView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_show_table);ed_mealname=findViewById(R.id.ed_mealname);ed_mealpy=findViewById(R.id.ed_mealpy);btn_query=findViewById(R.id.btn_query);btn_downmeal=findViewById(R.id.btn_downmeal);lsv_detail=findViewById(R.id.lsv_detail);btn_nextpage=findViewById(R.id.btn_nextpage);btn_uppage=findViewById(R.id.btn_uppage);tv_totalinfo=findViewById(R.id.tv_totalinfo);this.emptyView = findViewById(R.id.empty_view);btn_query.setOnClickListener(this);btn_downmeal.setOnClickListener(this);btn_nextpage.setOnClickListener(this);btn_uppage.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()){case R.id.btn_query:{DBManager.getInstance().init(ShowTable.this);List<String> qmlst=new ArrayList<>();mlst=DBManager.getInstance().getmeal(qmlst);myAdapter=new MyAdapter<dishmeal>(ShowTable.this , (ArrayList)mlst,R.layout.table_row,emptyView) {@Overridepublic void bindView(ViewHolder holder, dishmeal obj) {//设置值及对应列宽度(根据表头列的宽度)//注意各列的宽度和表头列的宽度要相同,否则会显示错位 ((TextView)findViewById(R.id.tab_th_col0)).getWidth()holder.setText(R.id.tab_row_col0, obj.getMealName(),((TextView)findViewById(R.id.tab_th_col0)).getWidth());holder.setText(R.id.tab_row_col1, String.valueOf(obj.getSellPrice()),((TextView)findViewById(R.id.tab_th_col1)).getWidth());holder.setText(R.id.tab_row_col2, "1",((TextView)findViewById(R.id.tab_th_col2)).getWidth());//设置隐藏及对应列宽度holder.setVisibility(R.id.tab_row_col3,1,((TextView)findViewById(R.id.tab_th_col3)).getWidth());holder.setVisibility(R.id.tab_row_col4,1,((TextView)findViewById(R.id.tab_th_col4)).getWidth());holder.setVisibility(R.id.tab_row_col5,0);holder.setVisibility(R.id.tab_row_btn,1,((Button)findViewById(R.id.tab_th_btn)).getWidth());//点击事件holder.setOnClickListener(R.id.tab_row_btn, new View.OnClickListener() {@Overridepublic void onClick(View v) {int iv=holder.getItemPosition();dishmeal m=mlst.get(iv);//Logger.d("dishmeal-"+iv+":"+ JSON.toJSONString(m));m.setSellPrice(130);//更新第iv行的值myAdapter.update(iv,m);}});}};lsv_detail.setAdapter(myAdapter);break;}case R.id.btn_downmeal:{break;}case R.id.btn_nextpage:{break;}case R.id.btn_uppage:{break;}default:{break;}}}}

四、MyAdapter  代码

CSDN

相关文章:

Android Studio 动态表格显示效果

最终效果 一、先定义明细的样式 table_row.xml <?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_h…...

Python 全栈系列264 使用kafka进行并发处理

说明 暂时考虑的场景是单条数据处理特别复杂和耗时的场景。 场景如下&#xff1a; 要对一篇文档进行实体处理&#xff0c;然后再对实体进行匹配。在这个过程当中&#xff0c;涉及到了好几部分服务&#xff1a; 1 实体识别服务2 数据库查询服务3 es查询服务 整个处理包成了服…...

【安全靶场】-DC-7

❤️博客主页&#xff1a; iknow181 &#x1f525;系列专栏&#xff1a; 网络安全、 Python、JavaSE、JavaWeb、CCNP &#x1f389;欢迎大家点赞&#x1f44d;收藏⭐评论✍ 一、收集信息 1.查看主机是否存活 nmap -T4 -sP 192.168.216.149 2.主动扫描 看开放了哪些端口和功能 n…...

0065__windows开发要看的经典书籍

windows开发要看的经典书籍_window编程书籍推荐-CSDN博客...

第133天:内网安全-横向移动域控提权NetLogonADCSPACKDC永恒之蓝

案例一&#xff1a;横向移动-系统漏洞-CVE-2017-0146 这个漏洞就是大家熟悉的ms17-010&#xff0c;这里主要学习cs发送到msf&#xff0c;并且msf正向连接后续 原因是cs只能支持漏洞检测&#xff0c;而msf上有很多exp可以利用 注意msf不能使用4.5版本的有bug 这里还是反弹权…...

【IoTDB 线上小课 06】列式写入=时序数据写入性能“利器”?

【IoTDB 视频小课】更新来啦&#xff01;今天已经是第六期了~ 关于 IoTDB&#xff0c;关于物联网&#xff0c;关于时序数据库&#xff0c;关于开源... 一个问题重点&#xff0c;3-5 分钟&#xff0c;我们讲给你听&#xff1a; 列式写入到底是&#xff1f; 上一期我们详细了解了…...

【机器学习】小样本学习的实战技巧:如何在数据稀缺中取得突破

我的主页&#xff1a;2的n次方_ 在机器学习领域&#xff0c;充足的标注数据通常是构建高性能模型的基础。然而&#xff0c;在许多实际应用中&#xff0c;数据稀缺的问题普遍存在&#xff0c;如医疗影像分析、药物研发、少见语言处理等领域。小样本学习&#xff08;Few-Shot Le…...

2024.08.14 校招 实习 内推 面经

地/球&#x1f30d; &#xff1a; neituijunsir 交* 流*裙 &#xff0c;内推/实习/校招汇总表格 1、校招 | 理想汽车2025“理想”技术沙龙开启报名 校招 | 理想汽车2025“理想”技术沙龙开启报名 2、校招 | 紫光国芯2025校园招聘正式启动 校招 | 紫光国芯2025校园招聘正式…...

国产双通道集成电机一体化应用的电机驱动芯片-SS6951A

电机驱动芯片 - SS6951A为电机一体化应用提供一种双通道集成电机驱动方案。SS6951A有两路H桥驱动&#xff0c;每个H桥可提供较大峰值电流4.0A&#xff0c;可驱动两个刷式直流电机&#xff0c;或者一个双极步进电机&#xff0c;或者螺线管或者其它感性负载。双极步进电机可以以整…...

32 - II. 从上到下打印二叉树 II

comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9832%20-%20II.%20%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E6%89%93%E5%8D%B0%E4%BA%8C%E5%8F%89%E6%A0%91%20II/README.md 面试题 32 - II. 从上到下打…...

總結熱力學_3

參考: 陈曦<<热力学讲义>>http://ithatron.phys.tsinghua.edu.cn/downloads/thermodynamics.pdf 4 热力学量的测量 4.3 主温度计 常用的气体温度计有等体积气体温度计、声学气体温度计和介电常数气体温度计。很多气体在水的三相点附近都接近理想气体。但真正的理…...

TypeScript学习笔记1---认识ts与js的异同、ts的所有数据类型详解

前言&#xff1a;去年做过几个vue3js的项目&#xff0c;当时考虑到时间问题&#xff0c;js更加熟悉&#xff0c;学习成本低一点&#xff0c;所以只去了解了vue3。最近这段时间补了一下ts的知识点&#xff0c;现今终于有空来码文章了&#xff0c;做个学习总结&#xff0c;方便以…...

华为数通方向HCIP-DataCom H12-821题库(更新单选真题:1-10)

第1题 1、下面是一台路由器的部分配置,关于该配置描述正确的是? [HUAWEllact number 2001 [HUAWEl-acl-basic-2001]rule 0 permit source 1.1.1.1 0 [HUAWEl-acl-basic-2001]rule 1 deny source 1.1.1.0 0 [HUAWEl-acl-basic-2001]rule...

【车载开发系列】单片机烧写的文件

【车载开发系列】单片机烧写的文件 【车载开发系列】单片机烧写的文件 【车载开发系列】单片机烧写的文件一. 什么是bin二. 什么是Hex三. 什么是Motorola S-record&#xff08;S19&#xff09;四. ELF格式五. Bin与Hex文件的比对六. 单片机烧写文件的本质 一. 什么是bin bin是…...

pyqt 用lamada关联信号 传递参数 循环

在PyQt中&#xff0c;使用lambda函数来关联信号并传递参数是一个常见的做法&#xff0c;尤其是在需要为不同的对象实例关联不同的槽函数参数时。但是&#xff0c;需要注意的是&#xff0c;直接使用lambda可能会导致一些不易察觉的错误&#xff0c;尤其是当它在循环中使用时。这…...

adb命令

adbclient adbserver adbd 三者之间的关系 adbclient, adbserver, 和 adbd 是 Android Debug Bridge (ADB) 组件中的三个主要组成部分。它们各自扮演着不同的角色&#xff0c;共同协作来实现设备调试和管理的功能。下面我将详细介绍这三个组件之间的关系&#xff1a; adbd (A…...

Spring Boot项目热部署

Spring Boot项目热部署是什么 Spring Boot项目热部署是一种开发时的优化技术&#xff0c;可以使开发人员在修改代码后不需要重新启动应用程序即可实时看到修改的效果。在传统的开发模式中&#xff0c;每次修改代码后都需要重新编译、打包和部署应用程序&#xff0c;这样会浪费大…...

Chat App 项目之解析(八)

Chat App 项目介绍与解析&#xff08;一&#xff09;-CSDN博客文章浏览阅读340次&#xff0c;点赞7次&#xff0c;收藏3次。Chat App 是一个实时聊天应用程序&#xff0c;旨在为用户提供一个简单、直观的聊天平台。该应用程序不仅支持普通用户的注册和登录&#xff0c;还提供了…...

CAAC无人机飞行执照:学习内容与考试流程详解

CAAC无人机飞行执照的学习内容与考试流程是无人机爱好者及从业者必须了解的重要信息。以下是对这两方面的详细解析&#xff1a; 学习内容 CAAC无人机飞行执照的学习内容涵盖了多个方面&#xff0c;以确保学员能够全面掌握无人机飞行和应用的技能。主要学习内容包括&#xff1a…...

苹果手机怎么连接蓝牙耳机?3个方案,3秒连接

在快节奏的现代生活中&#xff0c;无线蓝牙耳机因其便捷性和自由度成为了许多人的首选。那么&#xff0c;苹果手机怎么连接蓝牙耳机呢&#xff1f;本文将为您介绍3种快速连接苹果设备与蓝牙耳机的方案&#xff0c;让您在享受音乐、通话或观看视频时&#xff0c;不再受线缆束缚&…...

RestClient

什么是RestClient RestClient 是 Elasticsearch 官方提供的 Java 低级 REST 客户端&#xff0c;它允许HTTP与Elasticsearch 集群通信&#xff0c;而无需处理 JSON 序列化/反序列化等底层细节。它是 Elasticsearch Java API 客户端的基础。 RestClient 主要特点 轻量级&#xff…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

AI Agent与Agentic AI:原理、应用、挑战与未来展望

文章目录 一、引言二、AI Agent与Agentic AI的兴起2.1 技术契机与生态成熟2.2 Agent的定义与特征2.3 Agent的发展历程 三、AI Agent的核心技术栈解密3.1 感知模块代码示例&#xff1a;使用Python和OpenCV进行图像识别 3.2 认知与决策模块代码示例&#xff1a;使用OpenAI GPT-3进…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

[10-3]软件I2C读写MPU6050 江协科技学习笔记(16个知识点)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...

基于Docker Compose部署Java微服务项目

一. 创建根项目 根项目&#xff08;父项目&#xff09;主要用于依赖管理 一些需要注意的点&#xff1a; 打包方式需要为 pom<modules>里需要注册子模块不要引入maven的打包插件&#xff0c;否则打包时会出问题 <?xml version"1.0" encoding"UTF-8…...

云原生玩法三问:构建自定义开发环境

云原生玩法三问&#xff1a;构建自定义开发环境 引言 临时运维一个古董项目&#xff0c;无文档&#xff0c;无环境&#xff0c;无交接人&#xff0c;俗称三无。 运行设备的环境老&#xff0c;本地环境版本高&#xff0c;ssh不过去。正好最近对 腾讯出品的云原生 cnb 感兴趣&…...

使用Matplotlib创建炫酷的3D散点图:数据可视化的新维度

文章目录 基础实现代码代码解析进阶技巧1. 自定义点的大小和颜色2. 添加图例和样式美化3. 真实数据应用示例实用技巧与注意事项完整示例(带样式)应用场景在数据科学和可视化领域,三维图形能为我们提供更丰富的数据洞察。本文将手把手教你如何使用Python的Matplotlib库创建引…...

Aspose.PDF 限制绕过方案:Java 字节码技术实战分享(仅供学习)

Aspose.PDF 限制绕过方案&#xff1a;Java 字节码技术实战分享&#xff08;仅供学习&#xff09; 一、Aspose.PDF 简介二、说明&#xff08;⚠️仅供学习与研究使用&#xff09;三、技术流程总览四、准备工作1. 下载 Jar 包2. Maven 项目依赖配置 五、字节码修改实现代码&#…...

华为OD机考-机房布局

import java.util.*;public class DemoTest5 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseSystem.out.println(solve(in.nextLine()));}}priv…...