我知道关于“getView 被调用了几次”这个问题几乎没有问题,但我的问题有点不同。
我有一个带有自定义行的自定义 listView(使用了 row_layout.xml)。 它通常运作良好。一开始我遇到了多次调用 getView 的问题,后来使用我在 stackoverflow 中看到的其中一种方法解决了这个问题。 (使用“usedPositions”数组)。
现在,我在日志中看到这种情况:getView pos 0、getView pos 1、getView pos 0、getView pos 1。 这导致我的行数增加了一倍。只有当我调用一个涵盖当前 Activity 的新 Activity 然后关闭该 Activity 时,它才会发生。 (例如,打开相机 Activity ,然后将其关闭)。
我将展示我的代码:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
Toast toast = Toast.makeText(this.context, "getView " + position, 1000);
toast.show();
String pos = Integer.toString(position);
if (!usedPositions.contains(pos)) {
CardHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new CardHolder();
//holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtCouponTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.txtBusinessName = (TextView)row.findViewById(R.id.txtBusinessName);
row.setTag(holder);
}
else
{
holder = (CardHolder)row.getTag();
}
Card card = data.get(position);
holder.txtCouponTitle.setText(card.couponTitle);
holder.txtBusinessName.setText(card.businessName);
//holder.imgIcon.setImageResource(card.icon);
TableLayout table = (TableLayout)row.findViewById(R.id.imagesTable);
for (int r=1; r<=1; r++){
TableRow tr = new TableRow(this.context);
for (int c=1; c<=10; c++){
ImageView im = new ImageView (this.context);
im.setImageDrawable(this.context.getResources().getDrawable(c<= card.numberOfStamps ? R.drawable.stamp_red :R.drawable.stamp_grey));
im.setPadding(6, 0, 0, 0); //padding in each image if needed
//add here on click event etc for each image...
//...
tr.addView(im, 40,40);
}
table.addView(tr);
}
// Your code to fill the imageView object content
usedPositions.add(pos); // holds the used position
}
else
usedPositions.remove(pos);
return row;
}
你能告诉我哪里出了问题吗?
最佳答案
This is not an issue, there is absolutely no guarantee on the order in which getView() will be called nor how many times.
所以你能处理的最好的是re-using the existing views (行布局)正确。
Here is another好帖子。
关于java - ListView - getView 被调用太多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9157523/
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候