我想提高列表视图的性能。
这是我的适配器中 getView 方法的代码?
public View getView(int arg0, View text_view_name, ViewGroup parent) {
try {
if (text_view_name == null) {
text_view_name = mInflater.inflate(
R.layout.bs_content_list_item1, null);
text_view_name.setTag(R.id.text1_detail1, text_view_name
.findViewById(R.id.text1_detail1));
text_view_name.setTag(R.id.text3_detail1, text_view_name
.findViewById(R.id.text3_detail1));
text_view_name.setTag(R.id.eve_img_detail1, text_view_name
.findViewById(R.id.eve_img_detail1));
}
text1 = (TextView) text_view_name.getTag(R.id.text1_detail1);
// text2 = (TextView) text_view_name.getTag(R.id.text2);
text3 = (TextView) text_view_name.getTag(R.id.text3_detail1);
img = (ImageView) text_view_name.getTag(R.id.eve_img_detail1);
text1.setText(VAL1[arg0]);
text3.setText(VAL3[arg0]);
if (!mBusy) {
img_value = new URL(VAL4[arg0]);
mIcon11 = BitmapFactory.decodeStream(img_value.openConnection()
.getInputStream());
img.setImageBitmap(mIcon11);
text_view_name.setTag(R.id.eve_img_detail1, null);
} else {
img.setImageResource(R.drawable.icon);
text_view_name.setTag(R.id.eve_img_detail1, text_view_name
.findViewById(R.id.eve_img_detail1));
}
} catch (Exception e) {
name = "Exception in MultiLine_bar_details1 getView";
Log.v(TAG, name + e);
}
return text_view_name;
}
这是 scrollstatechanged 方法的代码:
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_IDLE:
try {
MultiLine_bar_details1.mBusy = false;
int first = view.getFirstVisiblePosition();
int count = view.getCount();
for (int i = 0; i < count; i++) {
ImageView t = (ImageView) view.getChildAt(i);// here getting the ClassCastException
if (t.getTag(R.id.eve_img_detail1) != null) {
MultiLine_bar_details1.img_value = new URL(
MultiLine_bar_details1.VAL4[first + i]);
MultiLine_bar_details1.mIcon11 = BitmapFactory
.decodeStream(MultiLine_bar_details1.img_value
.openConnection().getInputStream());
MultiLine_bar_details1.img.setImageBitmap(MultiLine_bar_details1.mIcon11);
t.setTag(R.id.eve_img_detail1, null);
}
}
} catch (Exception e) {
Log.v(TAG, "Idle" + e);
}
// mStatus.setText("Idle");
break;
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
MultiLine_bar_details1.mBusy = true;
break;
case OnScrollListener.SCROLL_STATE_FLING:
MultiLine_bar_details1.mBusy = true;
break;
}
}
在空闲状态下获取异常:
05-03 16:47:15.201: VERBOSE/BS_Bars(258): Idlejava.lang.ClassCastException: android.widget.LinearLayout
这对我来说要正确获得输出非常复杂。实际上我有带有自定义适配器的列表视图。该图标使列表视图滚动非常缓慢。我从图像 url 获取图标的图像。至此(上面的代码)我可以提高我的列表视图的滚动性能。但图像图标的相应顺序不正确。当我滚动列表视图时,它会动态变化..
我参考了commonsware busy coder guide和这个博客。
编辑:我非常大的问题是“我们如何使用参数 AbsListView 访问滚动状态中的图像视图?”
有什么问题吗?如何做得更好?任何想法?