Listview+Service+download 更新不卡线程方法

安卓探究ListView+Adapter数据在工作线程中更新引发的crash以及解决方法(三) 第三部分 solution及测试   从上面的分析可以看出安卓希望的ListView+Adapter使用方式是更新数据,然后调用notifyDataSetChanged()触发重绘,整个过程在UI线程串行执行,框架逻辑会保证健壮可用。所以exception的描述也是说Make sure the content of your adapter is not modified from a b 阅读详情

方法:

要实现listview上进度条动态更新,一般我们可以采用2种方法:

1. 获得itemview对象,再获得其中的进度条等对象对其重新赋值

2. 通过更新数据源,再调用adapter的notifyDataSetChanged 方法




优劣:

第一种:能定位到item来更新。但是Adapter中的itemview是采用重用的方法,假如一个listview中一次能显示5个item,那么第6个item其实在重用第一个item,这样获得获得的itemview对象并不准确。

第二种:更新数据源,通过数据源中position下标与getView中的下标绑定,这样更新数据就能准确到指定的item。但是频繁调用getView方法,容易造成ui阻塞.




结合:

1. 拿到需要更新的数据源下表pos

2. 判断pos是否在listview的显示中

3. 在显示中则获得itemView对象

4. 更新对应的itemview对象数据



代码:

 1.获得pos是否在显示的listview中 , 及更新数据

 int firstVisibleRow = listview.getFirstVisiblePosition() -1;
                        int lasVisibleRow = listview.getLastVisiblePosition();
                        if(pos >= firstVisibleRow && pos<= lasVisibleRow){
                            View view = (View) listview.getChildAt(pos - firstVisibleRow);
                            ViewHolder holder = new ViewHolder();
                            holder.progressBar = (ProgressBar) view.findViewById(R.id.downloadPro_list_item);
                            holder.percentTv = (TextView)view.findViewById(R.id.percentTv_list_item);
                            holder.downloadImgBn = (ImageButton)view.findViewById(R.id.download_list_item);
                            holder.svvdTv = (TextView)view.findViewById(R.id.cargo_operation_list_svvd);
                            holder.portTv =(TextView)view.findViewById(R.id.cargo_operation_list_port);
                            holder.terminalTv = (TextView)view.findViewById(R.id.cargo_operation_list_terminal);
                            holder.etaTv = (TextView)view.findViewById(R.id.cargo_operation_list_eta);
                            updateUI(downloadInfo , holder );
                        }


优化:

1.可以通过修改发送handler的频率来进行优化

if(mesenger != null ){
            try {
                if((System.currentTimeMillis() - lastUpdatedTime > SEND_UPDATE_TIME)
                        || per >=100 || error!= NO_ERROR){
                    downloadInfo.setPer(getPer());
                    downloadInfo.setError(getError());
                    Message msg = Message.obtain();
                    msg.what = CargoOperationDownloadAdapter.UPDATE_UI;
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("DownloadInfo" , downloadInfo);
                    msg.setData(bundle);
                    mesenger.send(msg);
                    lastUpdatedTime = System.currentTimeMillis();
                }
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }


Windows本地部署Qwen3.5:0.8b:Ollama一键运行实战指南 大语言模型(LLM)本地化部署正成为开发者与企业提升数据安全、降低API成本的关键路径。其核心原理在于将模型推理引擎与硬件加速层(如DirectML、CUDA)深度耦合,实现低延迟、高兼容的端侧运行。技术价值体现在免依赖、轻量化、跨显卡兼容——尤其适合Windows环境下的边缘计算、离线办公与快速原型验证。典型应用场景包括笔记本AI助手、工业终端日志分析、企业内网文档摘要等。本文聚焦Qwen3.5:0.8b这一高性价比中文小模型,结合Ollama原生Windows方案,详解零基础安装、DirectML加速适 阅读详情

相关推荐

vLLM部署Llama系列大模型实战指南

大语言模型推理引擎是支撑私有化AI服务的核心基础设施,其性能直接决定低延迟、高吞吐与显存效率。vLLM凭借PagedAttention内存管理与Continuous Batching动态批处理技术,显著提升KV Cache利用率和请求吞吐能力,已成为Llama、Qwen等Decoder-only架构模型的首选推理框架。相比transformers静态批处理易OOM、llama.cpp CPU推理延迟抖动大等局限,vLLM在A10/A100等主流GPU上实现实测128+ QPS与亚秒级P99延迟,同时原生兼容

anwenzhao0749的博客 481

C#子线程中更新Listview内容(UI更新)

C#子线程中更新Listview内容(UI更新) 前言 Listview等控件内容的更新,在主线程中只需直接进行操作,但是在子线程中,直接操作就会报错。其实,不止C#中有这个现象,安卓中也有同样的现象。 这时候,可以借助delegate完成。 提示:以下是本篇文章正文内容,下面案例可供参考 一、delegate是什么? 示例:delegate委托是一个对方法进行引用的类型,当创建一个委托,也就创建一个引用方法的变量。 二、使用步骤 public delegate void UpdateStatus.

bianhu3124的博客 3440

第二次作业——Service、Listview与ACtivity参数传递

此代码为武汉理工大学秦珀石老师布置的武汉理工大学秦珀石第二次作业——Service、Listview与ACtivity参数传递,详情请戳:http://blog.youkuaiyun.com/qq347198688/article/details/52914407

用Python自动录制B站直播学习课程(附完整源码与防断流技巧)

本文详细介绍了如何使用Python自动化录制B站直播学习课程,涵盖M3U8流媒体协议解析、核心功能实现、稳定性增强与异常处理等关键技术。通过完整源码与防断流技巧,帮助开发者高效获取直播内容,适用于在线教育、技能培训等场景。

weixin_30263073的博客 381

Android 14密钥管理深度解析:从Keystore到Keymint的架构演进与Trusty安全实践

本文深入解析Android 14密钥管理系统的架构演进,从Keystore到Keymint的技术升级,以及Trusty安全环境的最佳实践。详细探讨了Keystore2的性能优化、Keymint的标准化设计,以及如何在Trusty TEE中实现安全密钥管理,为开发者提供构建现代密钥管理系统的实用指南。

weixin_42533120的博客 263

51单片机基础知识

前言 周末闲着无聊,以后定时更新一期关于51单片机的学习案例,以供大家平时参考使用。至于单片机,你可以理解为人的大脑,而人各项身体器官的运作需要意识给到大脑,然后大脑再驱动我们的中枢神经进行相应的动作,这里的意识可以理解为我们要写的程序,而人的器官相当于各种输出设备,例如我们以后要学的LED、电机、各种传感器等等。学好单片机能让你找到一份相对不错的工作,当然越可观的东西也是要付出相应努力的。 一、51单片机是什么? 通常我们一说到 51 单片机,指的都是兼容IntelMCS-51体系架构的一系列单片机,而

qq_43537819的博客 6905

Java嵌套类深度解析:从内存模型到设计模式应用

嵌套类是Java面向对象编程中的重要特性,通过在类内部定义另一个类实现逻辑封装。其核心原理涉及访问控制、隐式引用和闭包机制,分为静态成员类、非静态成员类、匿名类和局部类四种类型。在Android开发中,Handler等组件的内存泄漏问题常源于对嵌套类引用机制的理解不足。合理使用嵌套类能提升代码内聚性,实现迭代器、策略等设计模式,特别适合处理回调逻辑和复杂数据结构。现代Java中,Lambda表达式和Record类为嵌套类提供了更多替代方案,但理解其底层字节码实现和内存模型仍是优化性能的关键。

weixin_34050519的博客 389

Bode图、ABCD矩阵与EET结合:三步搞定复杂电路传递函数分析

在模拟电路与电源控制设计中,传递函数和频率响应是衡量系统稳定性的核心指标。Bode图以直观的幅频/相频曲线揭示带宽与相位裕度,ABCD二端口矩阵可将级联网络结构化表达,而EET额外元素定理则针对寄生电容、负载效应等局部修正提供显式公式。三者互补,组合成一套从整体拓扑到局部寄生修正的完整分析方法:先用ABCD搭建主体网络,再用EET快速加入额外元件,最后用Bode图验证传递函数和稳定裕度。该方法适用于滤波器设计、电源环路补偿、运放稳定性分析等线性小信号场景,支持Python/SciPy和SPICE交叉验证,显

weixin_32496547的博客 363

.NET Framework 1.0到4.0演进中的真实技术契约与迁移避坑指南

.NET Framework 是 Windows 平台企业级应用的底层运行基石,其核心由 CLR 运行时、BCL 类库和配置模型共同构成。从 1.0 到 4.0 的演进并非简单功能叠加,而是经历了四次底层契约重写:泛型引入重构 JIT 行为、CAS 安全模型确立权限边界、WCF/WPF 等技术整合带来跨组件互操作约束,以及 CLR 4.0 的并行运行时机制。这些变更深刻影响着程序集加载、ViewState 序列化、WCF 配置兼容性与 GAC 版本共存等关键环节。尤其在遗留系统迁移中,.NET Framew

416

【scratch音乐课】天空之城:音符与节拍、消息与链表

scratch是一个非常小巧的青少年编程工具,自带程序编写语句,积木式语句非常直观、易用,可创作数学、科学、音乐、绘画等方面作品。本文用scratch“演奏”一首大家非常熟悉的《天空之城》,并向大家介绍一些基本乐理知识,以及scratch中消息、链表的使用。

★·°立芯;︶︵︶ 1万+

基于STM32的智能手环心率血氧体温监测系统(完整设计)

本文设计了一款基于STM32单片机的多功能智能手环系统,集成心率、血氧、体温实时监测功能,并支持运动数据管理与健康预警。系统采用MAX30102传感器实现心率血氧监测,DS18B20检测体温,ADXL345进行步数统计,通过OLED屏幕显示数据。研究通过低功耗硬件选型与模块化软件架构设计,实现了多参数同步采集、阈值预警及蓝牙数据传输功能。测试结果表明,系统在健康监测精度、续航能力及用户交互体验上均达到预期目标,为个人健康管理提供了实用解决方案。

3254968421的博客 703

DownloadManager之DownloadService浅析

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33797791的博客 1236

48-OpenCVSharp —-Cv2.MatchTemplate() 函数功能(模板匹配)详解

是 OpenCV 中一个常见且简单的模板匹配算法,适用于目标检测和图像识别中的静态场景。它的优点是易于理解和实现,但在面对旋转、尺度变化、复杂背景或光照变化等挑战时,效果可能大打折扣。在这些情况下,结合多尺度图像、特征匹配算法(如 SIFT、SURF、ORB 等)以及深度学习模型可以显著提高匹配的鲁棒性和精度。模板匹配仍然是一个非常基础但强大的工具,适用于一些简单的图像匹配任务。对于更加复杂和动态的图像识别任务,我们通常会使用其他更加复杂的算法或者深度学习模型来处理。

weixin_45590420的博客 4523

关于多线程下动态加载ListView数据源的注意事项

关于listview更新数据和界面不同步时出现的问题

MrHuang_s_blog的博客 1676

安装 miniconda linux

安装 miniconda linux

jacke121的专栏 1万+

双目相机标定理论与编程实现

双目相机标定是计算机视觉中的重要任务,通过确定双目相机的内参和外参,可以实现立体视觉的深度感知和三维重建。通过使用OpenCV库提供的函数,我们可以方便地进行双目相机的标定工作。双目相机标定是计算机视觉中的重要任务,用于确定双目相机的内参和外参,以实现立体视觉的深度感知和三维重建。通过上述代码,我们可以获得左右相机的内参矩阵、畸变系数、旋转矩阵和平移矩阵等参数,从而完成双目相机的标定过程。使用双目相机采集一系列左右相机的图像,确保标定板在不同位置和角度下都能被双目相机拍摄到。函数来检测标定板的角点。

ByteKnight的博客 325

ListView动态更新

listview更新有两种方式:一种是通知Adapter更新,不更新Activity,一种是使用Handler。下面就使用notifyDataSetChanged()函数来更新listview 无法贴图,很遗憾,就帖代码吧:main.xml:http://schemas.android.com/apk/res/android"           android:orien

Java学习的专栏 9539

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

android 子线程更新listview,android-在单独的线程中填充listview

在一个活动中,我加载了一个列表视图的行,这花了很多时间,因此我将此任务放在一个单独的线程中以允许显示progressDialog.我做以下private void doMyStuff() {listItems.clear();progressDialog.show();new Thread(new Runnable() {@Overridepublic void run() {for () {li...

weixin_32822843的博客 441

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

解决WebView实现获得js中Function返回值

整理自:http://blog.sina.com.cn/s/blog_67ac56e70101ajlp.html 本文实现的是使用WebView调用js代码,并获得function的return值 1. 创建自定义的 MyWebView 并继承 WebView  public class MyWebView extends WebView {

4222

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

PhoneGap(Cordova) :js调用native(2) ------Android篇

本文讲解如何使用PhoneGap(Cordova) 调用Android中的方法

1930

CursorAdapter使用

1. Adapter的关系图  2. CursorAdapter构造函数 public CursorAdapter (Context context, Cursor c) Api11开始被弃用 public CursorAdapter (Context context, Cursor c, boolean autoRequery) autoeque

1228

IntentService(或非UI线程)中使用Toast

1.说明 Toast要求必须再UI线程中才能显示,Service默认是再主UI线程上

1064

LoaderManager.LoaderCallbacks的使用

文章为最简单使用记录笔记 1. 作用 实现异步查询 ,  提供了回调机制onLoadFinished()通知最终的运行结果 ,  实现Cursor监听,当改变的时候,进行查询,结果在onLoadFinished()中显示 2.使用  a) 继承 implements View.OnClickListener ,

995

借助Messenger令Intent存取handler

1. 存  intent.putExtra(EXTRA_MESSAGER,new Messenger(handler)); 2. 取

980
上一篇: Android实现ListView过滤功能,继承于BaseAdapter,非ArrayAdapter
下一篇: Android studio error : Failed to find target android-X
Cemmmmer
博客等级 码龄14年 3粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值