我使用horizontalView进行了listview。在这个ListView的每个位置都包含HorizontalView,其中有一组可以水平滚动的图像。Android notifydatasetchange()创建新的视图,同时需要更新视图中的布局位置维护
每当List在垂直滚动时达到其结尾时,我调用listview的notifydatasetchange()方法,这些实习生创建列表的新视图。
我的列表视图是这样
我的问题是:
假如我是在水平视图的图像12在ListView控件的0位置。当notifydatasetchange()调用它时会自动刷新所有视图,并且图像位置在ListView的位置0变为0。
用户再次为特定图像滚动&可能会让人恼火。
我需要在视图中保持图像的位置,以便在它重新加载时自动显示它在调用notifydatasetchange()之前的位置。
注:我使用两个适配器来填充ListView中的Horizontal scrollView。
适配器1
private class MyAdapter extends BaseAdapter {
private Context context;
private Activity activity;
private int count_processed_rows = 0;
MyAdapter(Activity activity, Context context) {
this.context = context;
this.activity = activity;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
int size = 0;
if((al_thumb_images != null) && (al_thumb_images.size() > 0)){
size = (al_thumb_images.size()/20) ;
}
return size;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//System.out.println("Parent position : "+position);
++count_processed_rows;
int processed_row_limit = getCount() * 2;
View row = convertView;
ViewHolder holder = null;
TextView textView_list_item = null;
if (row == null) {
holder = new ViewHolder();
LayoutInflater inflater_parent = this.activity.getLayoutInflater();
row = (View) inflater_parent.inflate(R.layout.listrow, null);
holder.linear = (HorizontalView) row.findViewById(R.id.gallery);
holder.linear.setId(position);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
try{
HorizontalImageAdapter imageAdapter = new HorizontalImageAdapter(activity, context, position);
holder.linear.setAdapter(imageAdapter);
} catch(Exception e){
System.out.println("catch :: "+e);
}
return row;
}
private class ViewHolder {
private HorizontalView linear;
}
}
Adapeter 2
private class HorizontalImageAdapter extends BaseAdapter {
private Activity activity;
private Context context;
private int list_row;
public HorizontalImageAdapter(Activity activity, Context context, int list_row) {
System.out.println(111);
this.activity = activity;
this.context = context;
this.list_row = list_row;
}
@Override
public int getCount() {
return 20;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
System.out.println(112);
View row = convertView;
ViewHolder holder = null;
if (row == null) {
holder = new ViewHolder();
LayoutInflater inflater_child = this.activity.getLayoutInflater();
row = (View) inflater_child.inflate(R.layout.listitem, null, false);
holder.image = (ImageView) row.findViewById(R.id.image);
holder.progress = (ProgressBar) row.findViewById(R.id.progress);
holder.checkBox_image = (CheckBox) row.findViewById(R.id.checkBox_image);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
try{
{
int limit = ((this.list_row) * 20) + position;
System.out.println(TAG+" --> "+"position : "+position);
System.out.println(TAG+" --> "+"list_row : "+this.list_row);
System.out.println(TAG+" --> "+"limit : "+limit);
System.out.println(TAG+" --> "+" i : "+((this.list_row) * 20));
System.out.println(TAG+" --> "+"al.size() : "+al_thumb_images.size());
int counter = 0;
final String s_THUMB_IMAGE_URL = al_thumb_images.get(limit);
counter++;
aq.id(holder.image).progress(holder.progress).image(s_THUMB_IMAGE_URL, true, true, 500, R.drawable.ic_launcher);
}
} catch(Exception e){
System.out.println("catch :: "+e);
}
return row;
}
private class ViewHolder {
ImageView image;
ProgressBar progress;
TextView icon_text;
CheckBox checkBox_image;
}
}