Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DecodeTask extends AsyncTask<String, Void, Bitmap> {
- private static int MaxTextureSize = 2048; /* True for most devices. */
- public ImageView v;
- public DecodeTask(ImageView iv) {
- v = iv;
- }
- protected Bitmap doInBackground(String... params) {
- BitmapFactory.Options opt = new BitmapFactory.Options();
- opt.inPurgeable = true;
- opt.inPreferQualityOverSpeed = false;
- opt.inSampleSize = 1;
- Bitmap bitmap = null;
- if(isCancelled()) {
- return bitmap;
- }
- opt.inJustDecodeBounds = true;
- BitmapFactory.decodeFile(params[0], opt);
- while(opt.outHeight > MaxTextureSize || opt.outWidth > MaxTextureSize) {
- opt.inSampleSize++;
- BitmapFactory.decodeFile(params[0], opt);
- }
- opt.inJustDecodeBounds = false;
- bitmap = BitmapFactory.decodeFile(params[0], opt);
- return bitmap;
- }
- @Override
- protected void onPostExecute(Bitmap result) {
- if(v != null) {
- v.setImageBitmap(result);
- }
- }
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView iv = null;
- if(convertView == null) {
- convertView = getLayoutInflater().inflate(R.id.your_view, null); /* Inflate your view here */
- iv = convertView.findViewById(R.id.your_image_view);
- } else {
- iv = convertView.findViewById(R.id.your_image_view);
- DecodeTask task = (DecodeTask)iv.getTag(R.id.your_image_view);
- if(task != null) {
- task.cancel(true);
- }
- }
- iv.setImageBitmap(null);
- DecodeTask task = new DecodeTask(iv);
- task.execute(getItem(position) /* File path to image */);
- iv.setTag(R.id.your_image_view, task);
- return convertView;
- }
- listView.setOnScrollListener(new OnScrollListener() {
- @Override
- public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
- int totalItemCount) {
- // Don't care.
- }
- @Override
- public void onScrollStateChanged(final AbsListView view, int scrollState) {
- // Load images here. ListView can tell you what rows are visible, you load images for these rows and update corresponding View-s.
- }
- })
- private class CallService extends AsyncTask<String, Integer, String>
- {
- protected String doInBackground(String... u)
- {
- fetchReasons();
- return null;
- }
- protected void onPreExecute()
- {
- //Define the loader here.
- }
- public void onProgressUpdate(Integer... args)
- {
- }
- protected void onPostExecute(String result)
- {
- //remove loader
- //Add data to your view.
- }
- }
- public void fetchReasons()
- {
- //Call Your Web Service and save the records in the arrayList
- }
- @Override
- public long getItemViewType(int position) {
- return position;
- }
- @Override
- public long getItemViewCount(int position) {
- return getCount();
- }
- @Override
- public View getView(int position, View convertView, ViewGroup arg2) {
- if (convertView == null) {
- //inflate your convertView and set everything
- }
- //do not do anything just return the convertView
- return convertView;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement