我在自定义listview adaper中的getView()发生了异步调用,如下所示(最后一行):
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.list_posts_item, null);
holder.tvTitle=(TextView) rowView.findViewById(R.id.tvTitleNamePost);
holder.ivPrimaryImage=(ImageView) rowView.findViewById(R.id.ivPrimaryImage);
holder.ivPrimaryImage.setId(position);
holder.ivPrimaryImage.setTag(listOfPosts.get(position).getPostId());
holder.tvLocality=(TextView) rowView.findViewById(R.id.tvLocalityPosts);
holder.tvDateCreated=(TextView) rowView.findViewById(R.id.tvDateCreated);
holder.tvTitle.setText(listOfPosts.get(position).getTitle());
holder.ivPrimaryImage.setImageBitmap(listOfPosts.get(position).getImage());
holder.tvLocality.setText(listOfPosts.get(position).getLocality());
holder.tvDateCreated.setText(listOfPosts.get(position).getCreatedDate());
postId = listOfPosts.get(position).getPostId();
Image image = new Image();
image.setImg(holder.ivPrimaryImage);
if(!"N".equalsIgnoreCase(listOfPosts.get(position).getHasImage()))
new GetPrimaryImages().execute(image);
return rowView;
}
问题是,每次执行getView时都会发生异步调用。只有当考虑的项目是imageView时,我们才能限制通话吗?
答案 0 :(得分:0)
你不应该真正从getView()调用异步,尽量保持尽可能轻,并尝试通过正确使用viewholders和recycler视图尽可能少地调用它。我不是百分之百完成你剩下的代码的方式,所以这里有一个很好的run through of all the details.网上有很多其他的深度解释,将通过你需要了解的有关getView()性能的所有内容。
答案 1 :(得分:0)
这有助于:
def writeToKafka[K: ClassTag, V: ClassTag](rdd: RDD[(K, V)], topic: String, keySerializerClass: String, valueSerializerClass: String, brokers: String = producerBroker) = {
rdd.foreachPartition { partitionOfRecords =>
val producerProps: Properties = new Properties
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers)
producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, keySerializerClass)
producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, valueSerializerClass)
val producer = new KafkaProducer[K, V](producerProps)
partitionOfRecords.foreach { message =>
producer.send(new ProducerRecord[K, V](topic, message._1, message._2))
}
producer.close()
}
}