当前位置: 首页 > 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;不再受线缆束缚&…...

C++_核心编程_多态案例二-制作饮品

#include <iostream> #include <string> using namespace std;/*制作饮品的大致流程为&#xff1a;煮水 - 冲泡 - 倒入杯中 - 加入辅料 利用多态技术实现本案例&#xff0c;提供抽象制作饮品基类&#xff0c;提供子类制作咖啡和茶叶*//*基类*/ class AbstractDr…...

iOS 26 携众系统重磅更新,但“苹果智能”仍与国行无缘

美国西海岸的夏天&#xff0c;再次被苹果点燃。一年一度的全球开发者大会 WWDC25 如期而至&#xff0c;这不仅是开发者的盛宴&#xff0c;更是全球数亿苹果用户翘首以盼的科技春晚。今年&#xff0c;苹果依旧为我们带来了全家桶式的系统更新&#xff0c;包括 iOS 26、iPadOS 26…...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器

第一章 引言&#xff1a;语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域&#xff0c;文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量&#xff0c;支撑着搜索引擎、推荐系统、…...

VM虚拟机网络配置(ubuntu24桥接模式):配置静态IP

编辑-虚拟网络编辑器-更改设置 选择桥接模式&#xff0c;然后找到相应的网卡&#xff08;可以查看自己本机的网络连接&#xff09; windows连接的网络点击查看属性 编辑虚拟机设置更改网络配置&#xff0c;选择刚才配置的桥接模式 静态ip设置&#xff1a; 我用的ubuntu24桌…...

基于Springboot+Vue的办公管理系统

角色&#xff1a; 管理员、员工 技术&#xff1a; 后端: SpringBoot, Vue2, MySQL, Mybatis-Plus 前端: Vue2, Element-UI, Axios, Echarts, Vue-Router 核心功能&#xff1a; 该办公管理系统是一个综合性的企业内部管理平台&#xff0c;旨在提升企业运营效率和员工管理水…...

麒麟系统使用-进行.NET开发

文章目录 前言一、搭建dotnet环境1.获取相关资源2.配置dotnet 二、使用dotnet三、其他说明总结 前言 麒麟系统的内核是基于linux的&#xff0c;如果需要进行.NET开发&#xff0c;则需要安装特定的应用。由于NET Framework 是仅适用于 Windows 版本的 .NET&#xff0c;所以要进…...

游戏开发中常见的战斗数值英文缩写对照表

游戏开发中常见的战斗数值英文缩写对照表 基础属性&#xff08;Basic Attributes&#xff09; 缩写英文全称中文释义常见使用场景HPHit Points / Health Points生命值角色生存状态MPMana Points / Magic Points魔法值技能释放资源SPStamina Points体力值动作消耗资源APAction…...

拟合问题处理

在机器学习中&#xff0c;核心任务通常围绕模型训练和性能提升展开&#xff0c;但你提到的 “优化训练数据解决过拟合” 和 “提升泛化性能解决欠拟合” 需要结合更准确的概念进行梳理。以下是对机器学习核心任务的系统复习和修正&#xff1a; 一、机器学习的核心任务框架 机…...

虚幻基础:角色旋转

能帮到你的话&#xff0c;就给个赞吧 &#x1f618; 文章目录 移动组件使用控制器所需旋转&#xff1a;组件 使用 控制器旋转将旋转朝向运动&#xff1a;组件 使用 移动方向旋转 控制器旋转和移动旋转 缺点移动旋转&#xff1a;必须移动才能旋转&#xff0c;不移动不旋转控制器…...