本文介绍了与costumized BaseAdapter Scrolable ListView的很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个costumized BaseAdapter为我的ListView与此code:I have a costumized BaseAdapter for my listView with this code:public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { } else { holder = (ViewHolder) convertView.getTag(); } convertView = mInflater.inflate(R.layout.user_submissions_customisation, null); holder = new ViewHolder(); holder.JournalName = (TextView) convertView.findViewById(R.id.JournalName); holder.SubmissionTitle = (TextView) convertView.findViewById(R.id.SubmissionTitle); holder.SubmissionDate = (TextView) convertView.findViewById(R.id.SubmissionDate); holder.statusOk=(ImageView)convertView.findViewById(R.id.statusOkImage); holder.statusRejected=(ImageView)convertView.findViewById(R.id.statusRejectedImage); holder.statusProcessing=(ImageView)convertView.findViewById(R.id.statusProcessingImage); convertView.setTag(holder); ImageView statusOk=(ImageView)convertView.findViewById(R.id.statusOkImage); ImageView statusRejected=(ImageView)convertView.findViewById(R.id.statusRejectedImage); ImageView statusProcessing=(ImageView)convertView.findViewById(R.id.statusProcessingImage); MDPIActivity mdpi = new MDPIActivity(); Context context =mdpi.getContext(); LocalDatabase localDatabase = new LocalDatabase(context); //Instantiation of the DB int status = localDatabase.getSubmissionStatus(position+1); if (status==102 | status==19) { statusRejected.setVisibility(View.VISIBLE); } else { if (status==29) { statusOk.setVisibility(View.VISIBLE); } else { statusProcessing.setVisibility(View.VISIBLE); } } holder.JournalName.setText(submissionsArrayList.get(position).getJournalTitle()+"-"+submissionsArrayList.get(position).getID()); holder.SubmissionTitle.setText(submissionsArrayList.get(position).getTitle()); holder.SubmissionDate.setText(submissionsArrayList.get(position).getDate()); return convertView;} static class ViewHolder { TextView JournalName; TextView SubmissionTitle; TextView SubmissionDate; ImageView statusOk; ImageView statusRejected; ImageView statusProcessing; }所有作品WEL但列表的显示器上创建和滚动是pretty慢。我用这对EY列表太:All works wel but the creation of the list on the display and the scrolling is pretty slow.I used this for éy list too:android:fastScrollEnabled="true"android:scrollingCache="true"android:smoothScrollbar="true"但是,从previeous视图列表视图改变看法是缓慢和列表的滚动太But the view changing from the previeous view to the listview is slow and the scrolling of the list too.问题出在哪里?推荐答案全部拆开第一个做这件事情结果移动此code中,如果条件时,转换的观点是空搜索结果 convertView = mInflater.inflate(R.layout.user_submissions_customisation,NULL); 持有人=新ViewHolder(); holder.JournalName =(TextView中)convertView.findViewById(R.id.JournalName); holder.SubmissionTitle =(TextView中)convertView.findViewById(R.id.SubmissionTitle); holder.SubmissionDate =(TextView中)convertView.findViewById(R.id.SubmissionDate); holder.statusOk =(ImageView的)convertView.findViewById(R.id.statusOkImage); holder.statusRejected =(ImageView的)convertView.findViewById(R.id.statusRejectedImage); holder.statusProcessing =(ImageView的)convertView.findViewById(R.id.statusProcessingImage); convertView.setTag(架); 搜索结果您没有有效地利用适配器由像你一样的编码结果上面的方法将提高一定的性能结果在简单地说,你只能当转换视图为空夸大为列表行的看法。结果此外,在该行的观点,不同意见必须与本身convertView初始化。照片然后您可设置持有者观为标签的转换视图和适配器将持续提供,而不是膨胀的新的每一个相同的看法。时间搜索结果编辑:您应该移动code获取上下文,并从getView()方法实例化DB结果只是做一个类级别的变量 mContext在您的适配器类和实例在你的适配器通过传递活动的上下文的构造。结果然后,在同一个地方(构造函数)实例化分贝也。All apart first do this thingMove this code in the if condition when "convert view is null" convertView = mInflater.inflate(R.layout.user_submissions_customisation, null); holder = new ViewHolder(); holder.JournalName = (TextView) convertView.findViewById(R.id.JournalName); holder.SubmissionTitle = (TextView) convertView.findViewById(R.id.SubmissionTitle); holder.SubmissionDate = (TextView) convertView.findViewById(R.id.SubmissionDate); holder.statusOk=(ImageView)convertView.findViewById(R.id.statusOkImage); holder.statusRejected=(ImageView)convertView.findViewById(R.id.statusRejectedImage); holder.statusProcessing=(ImageView)convertView.findViewById(R.id.statusProcessingImage); convertView.setTag(holder);You are not using the adapter efficiently by coding as you did.The above way will improve the performance for sure.In nutshell, you must inflate the view for list row only when the convert view is null. Also, different views in the row's view must be initialized with the convertView itself.Then you set holder view as the tag to the convert view and the adapter will continuously provide the same view instead of inflating the new one every time.You should move the code for getting the context and instantiating the db from the getView() method.Just make a class level variable "mContext" in your adapter class and instantiate it in the constructor of your adapter by passing activity's context.Then at same place (constructor) instantiate the db also. 这篇关于与costumized BaseAdapter Scrolable ListView的很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-26 19:48