in Education by
i am new to android, so seeking some help on this what i am trying to do: i am downloading an xml file, loading it into an object, and displaying it using a layout inflator. within the xml there is a link to an image, i am then trying to launch a seperate asynctask to lazy load the images from the link given. the xml download works fine, its just the images bit i am struggling on. i think i am nearly there. any help would be greatly welcome my code: class MyRowAdapter extends ArrayAdapter { Activity context; MyRowAdapter (Activity context) { super(context, R.layout.news_row, items); this.context=context; } public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; if(row==null){ LayoutInflater inflater=context.getLayoutInflater(); row = inflater.inflate(R.layout.news_row, null); } XMLItem _item = items.get(position); rowpos = position; Log.v(TAG,""+position); TextView headline = (TextView)row.findViewById(R.id.Headline); headline.setText(_item.getHeadline()); TextView imagepath = (TextView)row.findViewById(R.id.Imagepath); imagepath.setText(_item.getImagepath()); try { ImageView img = (ImageView) row.findViewById(R.id.storyimage); img.setImageBitmap(_item.getBitmap()); } catch(IndexOutOfBoundsException e) { new DownloadImageTask().execute(_item.getImagepath()); } return row; } } private class DownloadImageTask extends AsyncTask{ private ImageView img; @Override protected Bitmap doInBackground(String... urls) { Bitmap bmImg = null; try { URL imageurl = new URL(urls[0]); Log.v("imageurl","="+imageurl); HttpURLConnection conn= (HttpURLConnection)imageurl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); //HttpURLConnection conn =(HttpURLConnection)imageurl.openConnection(); } return bmImg; } @Override protected void onPostExecute(Bitmap result) { // TODO Auto-generated method stub XMLItem _item = items.get(rowpos); super.onPostExecute(result); img.setImageBitmap(result); _item.setBitmap(result); Log.v("image task","onpostexecute"); myRowAdapter.notifyDataSetChanged(); } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Instead of implementing the separate task for downloading image from the specified URL, i would suggest you to implement: Android - How do I do a lazy load of images in ListView

Related questions

0 votes
    How to lazy load images? (a) Remove the rel attribute (b) Remove the src attribute (c) Make rel ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    I have these routes /items/:id /items /items/:id/edit ... etc I want to put the component, to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have these routes /items/:id /items /items/:id/edit ... etc I want to put the component, to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I've seen a few other solutions (Show activity Indicator while loading a lazy loaded Module in Angular 2, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    ____________ is one type of the simplest machine learning classification algorithms that is a subset of supervised ... R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    What is the initial step to set up a CSS Lazy Loading? (a) Fetching data (b) Loading the script ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    What is the purpose of lazy loading? (a) Immediate loading is necessary (b) Loading under command (c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
0 votes
    I have a problem with table-layout:fixed and width of inner columns if their content wider than column. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    I have a single window with a single custom view in it, and I want the custom view to resize ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    How can you create Fixed Layout with Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    The main objective of compressing (images / CSS / JavaScript) is to help with ____________. A. All the options B ... None of the Options D. Improving performance E. Reduce Overhead...
asked Feb 3, 2023 in Technology by JackTerrance
0 votes
    I try to print images with a for loop but the images dont load. The images are in the same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I try to print images with a for loop but the images dont load. The images are in the same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    Long story short...I have a base64 encoded string that I retrieve from a database. I need to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 28, 2022 in Education by JackTerrance
...