SHARE
TWEET

Untitled

a guest Jun 15th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ItemPhotoAdapter extends BaseAdapter {
  2.  
  3.     private ArrayList<ItemImageModel> arrItemImage;
  4.  
  5.     @Override
  6.     public ItemImageModel getItem(int i) {
  7.         return arrItemImage.get(i);
  8.     }
  9.  
  10.     ...
  11.  
  12.     @Override
  13.     public View getView(int i, View view, ViewGroup viewGroup) {
  14.         ViewHolder vh;
  15.         lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  16.  
  17.         if(view == null){
  18.             vh = new ViewHolder();
  19.             view = lf.inflate(R.layout.row_photo_grid, null);
  20.             vh.item_image = (ImageView) view.findViewById(R.id.img_item);
  21.  
  22.             view.setTag(vh);
  23.         } else {
  24.             vh = (ViewHolder) view.getTag();
  25.         }
  26.  
  27.  
  28.         ItemImageModel iim = arrItemImage.get(i);
  29.  
  30.         Picasso.with(context) //
  31.                 .load(iim.getResized()) //
  32.                 .placeholder(R.drawable.placeholder) //
  33.                 .error(R.drawable.error)
  34.                 .into(vh.item_image);
  35.  
  36.         vh.item_image.setOnClickListener(new OnImageClickListener(i));
  37.  
  38.         return view;
  39.     }
  40.  
  41.     ...
  42.  
  43.     private class OnImageClickListener implements View.OnClickListener {
  44.         int _position;
  45.  
  46.         public OnImageClickListener(int position) {
  47.             this._position = position;
  48.         }
  49.  
  50.         @Override
  51.         public void onClick(View view) {
  52.             Intent i = new Intent(context, PhotoGalleryActivity.class);
  53.             i.putExtra("position", _position);
  54.             context.startActivity(i);
  55.  
  56.         }
  57.     }
  58. }
  59.      
  60. public class PhotoGalleryActivity extends FragmentActivity {
  61.  
  62.     private ArrayList<ItemImageModel> arrItemImages;
  63.  
  64.     ...
  65.  
  66.     @Override
  67.     protected void onCreate(Bundle savedInstanceState) {
  68.         super.onCreate(savedInstanceState);
  69.         setContentView(R.layout.activity_photo_gallery);
  70.  
  71.         ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
  72.         pb = (ProgressBar) findViewById(R.id.loading);
  73.  
  74.         ActionBar actionBar = getActionBar();
  75.         actionBar.setDisplayHomeAsUpEnabled(true);
  76.  
  77.         arrItemImages = new ArrayList<ItemImageModel>();
  78.  
  79.         Intent i = getIntent();
  80.         final int position = i.getIntExtra("position", 1);
  81.         user_id = i.getStringExtra("user_id");
  82.         item_id = i.getStringExtra("item_id");
  83.  
  84. //        Log.d(TAG, "Image position: " + position);
  85.  
  86.         mAdapter = new PhotoGalleryAdapter(arrItemImages, getApplicationContext(), this);
  87.  
  88.         mViewPager.setAdapter(mAdapter);
  89.  
  90.         mViewPager.setCurrentItem(position);
  91.  
  92.         // ViewPagerIndicator
  93.         CirclePageIndicator titleIndicator = (CirclePageIndicator)findViewById(R.id.titles);
  94.         titleIndicator.setViewPager(mViewPager);
  95.  
  96.         loadPhotos();
  97.     }
  98.  
  99.     ...
  100.  
  101.     private void loadPhotos() {
  102.         mRequestQueue = Volley.newRequestQueue(this);
  103.  
  104.         String url = Constants.ITEM_DETAILS;
  105.  
  106.         GsonRequest<ItemDetailContainer> myReq = new GsonRequest<ItemDetailContainer>(
  107.                 Request.Method.GET, url, ItemDetailContainer.class,
  108.                 createMyReqSuccessListener(), createMyReqErrorListener());
  109.  
  110.         mRequestQueue.add(myReq);
  111.     }
  112.  
  113.     ...
  114. }
  115.      
  116. private Response.Listener<ItemDetailContainer> createMyReqSuccessListener() {
  117.     return new Response.Listener<ItemDetailContainer>() {
  118.         @Override
  119.         public void onResponse(ItemDetailContainer response) {
  120.             try {
  121.                 ...
  122.  
  123.                 mAdapter.notifyDataSetChanged();
  124.                 mViewPager.setCurrentItem(position); // this
  125.             } catch (Exception e) {
  126.                 e.printStackTrace();
  127.             }
  128.         };
  129.     };
  130. }
  131.      
  132. if (savedInstanceState != null) {
  133.     mLastTabIndex = savedInstanceState.getInt(KEY_TAB_INDEX, 0);
  134. } else {
  135.     mLastTabIndex = -1;
  136. }
  137.      
  138. mPostTypes = result.getTypes();
  139.  
  140. mAdapter.notifyDataSetChanged();
  141. if (mLastTabIndex > 0) {
  142.     mViewPager.setCurrentItem(mLastTabIndex);
  143. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top