1

나는 horizontalView로 listview를 만들었습니다. ListView의 각 위치에는 가로로 스크롤 할 수있는 이미지 세트가있는 HorizontalView가 있습니다.안드로이드 notifydatasetchange()는 레이아웃 위치와 함께 뷰에서 필요에 따라 새로운 뷰를 생성합니다. 유지

세로로 스크롤하는 동안 List가 끝까지 도달하면 interns는 listview의 notifydatasetchange() 메소드를 호출합니다.이 listview의 새로운 뷰가 생성됩니다. 내가 ListView에 위치 0에서 가로보기의 이미지 (12)에서 오전한다고 가정

:

내 목록보기이

enter image description here

enter image description here

내 문제 같은 것은 그이다. notifydatasetchange()를 호출하면 모든 뷰가 자동으로 새로 고쳐지고 ListView의 0 위치에서 이미지 위치가 0이됩니다.

특정 이미지에 대해 사용자가 다시 &으로 스크롤하는 것을 자극 할 수 있습니다.

이미지의 위치를 ​​유지해야하므로 notifydatasetchange()를 호출하기 전에 자동으로 다시로드됩니다.

참고 : 두 어댑터를 사용하여 ListView에서 가로 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; 
    } 

} 

답변

관련 문제