首页 文章 精选 留言 我的

精选列表

搜索[listview],共1040篇文章
优秀的个人博客,低调大师

android:ListView:convertView.setTag()来设置数据

void android.view.View.setTag(Objecttag) public voidsetTag(Object tag) Since: API Level 1 Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure. Parameters an Object to tag the view with also see getTag() setTag(int, Object) public View getView(int position, View convertView, ViewGroup parent) { final int cc = position; ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.itemrow, null); holder.tagcolor = (ImageView) convertView.findViewById(R.id.itemrowiamge); holder.itemname = (TextView) convertView.findViewById(R.id.itemrowtext); holder.cb = (CheckBox) convertView.findViewById(R.id.itemrowcb); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } //获取ViewHolder中所填入的数据 holder.tagcolor.setBackgroundResource((Integer) itemList.get(position).get("IMG")); holder.itemname.setText((String) itemList.get(position).get("ITEMNAME")); holder.ckd = (String) itemList.get(position).get("CHECKED"); //单个项目中的CheckBox的按键监听函数 holder.cb.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setC(cc);//当被按下后调用函数改变状态 } }); if (holder.ckd.equals("t")) holder.cb.setChecked(true); else holder.cb.setChecked(false); return convertView; } 设一个holder类 import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; //ViewHolder类用以储存每一条项目所需的数据 public class ViewHolder { public ImageView tagcolor;//单条项目中的图片 public TextView itemname;//单条项目中的文本 public CheckBox cb;//单条项目中的CheckBox public String ckd;//单条项目中用以标识CheckBox状态的字符串变量 } 即可。 本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2012/05/22/2512491.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android LruCache & DiskLruCache cooperate working in ListView

package zhangphil.cache; import android.app.ListActivity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.os.Bundle; import android.util.Log; import android.util.LruCache; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.security.MessageDigest; public class MainActivity extends ListActivity { private LruCache<String, Bitmap> mLruCache; private DiskLruCache mDiskLruCache; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int CACHE_SIZE = 8 * 1024 * 1024; mLruCache = new LruCache(CACHE_SIZE); try { mDiskLruCache = DiskLruCache.open(this.getCacheDir(), 1, 1, CACHE_SIZE * 10); } catch (Exception e) { e.printStackTrace(); } ArrayAdapter mAdapter = new ArrayAdapter(this, 0) { @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { ImageView image = new ImageView(getContext()); load(R.mipmap.ic_launcher, image); return image; } @Override public int getCount() { return 20; } }; setListAdapter(mAdapter); } private void load(int id, ImageView image) { String key = null; if (id == R.mipmap.ic_launcher) { key = getMD5("R.mipmap.ic_launcher"); } //首先查找LruCache中的缓存 Bitmap bmp = mLruCache.get(key); if (bmp == null) { Log.d("LruCache缓存", "没有,继续深入到DiskLruCache读取。"); bmp = readFromDiskLruCache(key); if (bmp == null) { Log.d("LruCache与DiskLruCache", "没有缓存,开始创建新数据资源并缓存之。"); bmp = BitmapFactory.decodeResource(getResources(), id); //初次创建新资源,更新到DiskLruCache writeToDiskLruCache(key, bmp); } else { image.setImageBitmap(bmp); } //更新到LruCache缓存中,以待下一次使用。 mLruCache.put(key, bmp); Log.d("LruCache缓存", "写入完成。"); } else { //命中缓存 Log.d("LruCache缓存", "已有,复用。"); image.setImageBitmap(bmp); } } private void writeToDiskLruCache(String key, Bitmap bmp) { try { DiskLruCache.Editor editor = mDiskLruCache.edit(key); //把Bitmap转化为byte数组存储 ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] bytes = baos.toByteArray(); //再次把Bitmap数组写进为DiskLruCache准备的输出流。 OutputStream os = editor.newOutputStream(0); os.write(bytes); os.flush(); //正式写入DiskLruCache editor.commit(); Log.d("DiskLruCache缓存", "写入缓存资源完毕。"); } catch (Exception e) { e.printStackTrace(); } } private Bitmap readFromDiskLruCache(String key) { DiskLruCache.Snapshot snapShot = null; try { snapShot = mDiskLruCache.get(key); } catch (Exception e) { e.printStackTrace(); } Bitmap bmp = null; if (snapShot != null) { Log.d("DiskLruCache缓存", "发现资源,复用。"); InputStream is = snapShot.getInputStream(0); bmp = BitmapFactory.decodeStream(is); } else { Log.d("DiskLruCache缓存", "没有发现缓存资源。"); } return bmp; } private String getMD5(String msg) { MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (Exception e) { e.printStackTrace(); } md.reset(); md.update(msg.getBytes()); byte[] bytes = md.digest(); String result = ""; for (byte b : bytes) { result += String.format("%02x", b); } return result; } }

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册