我使用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;
}
}