1

私はHorizo​​ntalViewでリストビューを作成しました。この ListView の各位置には、水平方向にスクロールできる一連の画像がある Horizo​​ntalView が含まれています。

リストが垂直方向にスクロールしているときにリストが最後に到達するたびに、リストビューの notifydatasetchange() メソッドを呼び出します。このメソッドは、インターンがリストの新しいビューを作成します。

マイリストビューはこんな感じ

ここに画像の説明を入力

ここに画像の説明を入力

私の問題は次のとおりです。

ListView の位置 0 にある水平ビューの画像 12 にいるとします。notifydatasetchange() が呼び出されると、すべてのビューが自動的に更新され、Image の位置が ListView の位置 0 で 0 になります。

ユーザーが特定の画像を何度もスクロールするのはイライラすることがあります。

ビュー上の画像の位置を維持する必要があるため、リロードすると、notifydatasetchange() を呼び出す前と同じように自動的に表示されます。

注 : ListView に Horizo​​ntal scrollView を設定するために 2 つのアダプターを使用しています。

アダプター 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;
    }

}

アダプター 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;
    }

}
4

1 に答える 1