FullScreenViewSlider return position 0 1 (viewpager)

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Apr 3, 2015 6:12:14 PM via Website

Hey ,

I have problems in my adpater when I click on picture still look back position 0 my array !!

public class FullScreenImageAdapter extends PagerAdapter {

private Activity _activity;
private ArrayList<String> _imagePaths;
private LayoutInflater inflater;
private int _pos_act;
private static  ImageLoader mImageLoader;
private static String TAG = FullScreenImageAdapter.class.getSimpleName();
private View viewLayout;

// constructor
public FullScreenImageAdapter(Activity activity, int pos) {
    this._activity = activity;
    this._imagePaths = new ArrayList<String>();
    this._pos_act =  pos ;
    this.getImagePaths();
}
public void getImagePaths()
{
    String urlJsonArry = "";
    JsonArrayRequest req = new JsonArrayRequest(urlJsonArry,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, response.toString());

                    try {
                        Log.d(TAG, "Count = " + response.length());
                        for (int i = 0; i < response.length(); i++) 
                        {

                            JSONObject thumbs= (JSONObject) response.get(i);

                            String thumb= thumbs.getString("thumb");
                            _imagePaths.add(thumb);
                        //    Log.d(TAG,thumb);
                           // Log.d(TAG,_imagePaths.toString()+"pppppppppppp");
                        }
                      //  Log.d(TAG, "filePaths (1) = " + _imagePaths.toString());

                    } catch (JSONException e) {
                        /*e.printStackTrace();
                        Toast.makeText(_context,
                                "Error: " + e.getMessage(),
                                Toast.LENGTH_LONG).show();
                        */
                    }
                 FullScreenImageAdapter.this.notifyDataSetChanged();
                   // hidepDialog();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    /*
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    Toast.makeText(_context,
                            error.getMessage(), Toast.LENGTH_SHORT).show();
                   // hidepDialog();
                   */
                }
            });

    AppController.getInstance().addToRequestQueue(req);
}



@Override
public Object instantiateItem(ViewGroup container, int position) 
{
    NetworkImageView imgDisplay;
    Button btnClose;

    inflater = (LayoutInflater) _activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
            false);

    imgDisplay = (NetworkImageView) viewLayout.findViewById(R.id.imgDisplay);
    btnClose = (Button) viewLayout.findViewById(R.id.btnClose);

    mImageLoader = AppController.getInstance().getImageLoader();
    ImageListener listener = ImageLoader.getImageListener(imgDisplay, android.R.drawable.gallery_thumb, android.R.drawable.ic_delete);

    imgDisplay.setImageUrl(_imagePaths.get(position), mImageLoader);
   // mImageLoader.get(url.toString(), listener);

    Log.d(TAG ,"Position adapter  : " + position );

    Toast.makeText(_activity, " " +"Position VAL : " + _imagePaths.get(position)+ "   Position : " + position , Toast.LENGTH_SHORT).show();

    btnClose.setOnClickListener(new View.OnClickListener() {            
        @Override
        public void onClick(View v) {
            _activity.finish();

        }
    }); 

    ((ViewPager) container).addView(viewLayout , 0);

    return viewLayout;
}
@Override
public int getCount() {
    return this._imagePaths.size();
}

public Object getItem(int position) {
    return this._imagePaths.get(getPosition(position));
}

public int getPosition(int position) {
    return _imagePaths.size() - 1 - position;
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == ((RelativeLayout) object);

}

@Override
public void destroyItem(ViewGroup container, int _pos, Object object) {
    ((ViewPager) container).removeView((RelativeLayout) object);

}

}