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

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录

ASP.NET Core 是一个跨平台的开源框架&#xff0c;用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录&#xff0c;以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...

零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?

一、核心优势&#xff1a;专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发&#xff0c;是一款收费低廉但功能全面的Windows NAS工具&#xff0c;主打“无学习成本部署” 。与其他NAS软件相比&#xff0c;其优势在于&#xff1a; 无需硬件改造&#xff1a;将任意W…...

高频面试之3Zookeeper

高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个&#xff1f;3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制&#xff08;过半机制&#xff0…...

连锁超市冷库节能解决方案:如何实现超市降本增效

在连锁超市冷库运营中&#xff0c;高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术&#xff0c;实现年省电费15%-60%&#xff0c;且不改动原有装备、安装快捷、…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院挂号小程序

一、开发准备 ​​环境搭建​​&#xff1a; 安装DevEco Studio 3.0或更高版本配置HarmonyOS SDK申请开发者账号 ​​项目创建​​&#xff1a; File > New > Create Project > Application (选择"Empty Ability") 二、核心功能实现 1. 医院科室展示 /…...

电脑插入多块移动硬盘后经常出现卡顿和蓝屏

当电脑在插入多块移动硬盘后频繁出现卡顿和蓝屏问题时&#xff0c;可能涉及硬件资源冲突、驱动兼容性、供电不足或系统设置等多方面原因。以下是逐步排查和解决方案&#xff1a; 1. 检查电源供电问题 问题原因&#xff1a;多块移动硬盘同时运行可能导致USB接口供电不足&#x…...

学校招生小程序源码介绍

基于ThinkPHPFastAdminUniApp开发的学校招生小程序源码&#xff0c;专为学校招生场景量身打造&#xff0c;功能实用且操作便捷。 从技术架构来看&#xff0c;ThinkPHP提供稳定可靠的后台服务&#xff0c;FastAdmin加速开发流程&#xff0c;UniApp则保障小程序在多端有良好的兼…...

【JavaWeb】Docker项目部署

引言 之前学习了Linux操作系统的常见命令&#xff0c;在Linux上安装软件&#xff0c;以及如何在Linux上部署一个单体项目&#xff0c;大多数同学都会有相同的感受&#xff0c;那就是麻烦。 核心体现在三点&#xff1a; 命令太多了&#xff0c;记不住 软件安装包名字复杂&…...

【开发技术】.Net使用FFmpeg视频特定帧上绘制内容

目录 一、目的 二、解决方案 2.1 什么是FFmpeg 2.2 FFmpeg主要功能 2.3 使用Xabe.FFmpeg调用FFmpeg功能 2.4 使用 FFmpeg 的 drawbox 滤镜来绘制 ROI 三、总结 一、目的 当前市场上有很多目标检测智能识别的相关算法&#xff0c;当前调用一个医疗行业的AI识别算法后返回…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...