Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:25:12+00:00 2026-06-18T04:25:12+00:00

I need to parse and display url content in listview. I have parsed title,date,

  • 0

I need to parse and display url content in listview. I have parsed title,date, content,name and image using lazyloading but now i need to parse url and display its content in listview.
But the problem here instead of diplaying url it is displaying image url. It is displaying like this http://imageshack.us/photo/my-images/18/device20130202121840.png/ following is my json response(only few response included here) and parsing code

"posts": [
    {
        "id": 2954,
        "type": "ad_listing",
        "slug": "commander-retreat-for-sale",
        "url": "http://avoidserum/ads/commander-retreat-for-sale/",
        "status": "publish",
        "title": "Commander Retreat for sale",
        "title_plain": "Commander Retreat for sale",
        "content": "<p>Commander Retreat : Hebbal Lake<br />\n2 BHK<br />\nBuilt up: 1180sft<br />\n3rd floor<br />\nTotal G+3 floors<br />\nWest facing<br />\nFurnished<br />\nSale price Rs. 50lacs ( nego)<br />\nFor further details please call M/s. Farid Consultants @ 9844106901 /9880123548<br />\nEmail: manjula@faridconsultants.com</p>\n",
        "excerpt": "Commander Retreat : Hebbal Lake 2 BHK Built up: 1180sft 3rd floor Total G+3 floors West facing Furnished Sale price Rs. 50lacs ( nego) For further details please call M/s. Farid Consultants @ 9844106901 /9880123548 Email: manjula@faridconsultants.com",
        "date": "2013-02-01 05:09:58",
        "modified": "2013-02-01 05:09:58",
        "categories": [],
        "tags": [],
        "author": {
            "id": 344,
            "slug": "ruby",
            "name": "Ruby",
            "first_name": "",
            "last_name": "",
            "nickname": "Ruby",
            "url": "",
            "description": ""
        },
        "comments": [],
        "attachments": [
            {
                "id": 2955,
                "url": "http://imageurl/wp-content/uploads/2013/01/785862.jpg",
                "slug": "commander-retreat-for-sale",
                "title": "Commander Retreat for sale",
                "description": "",
                "caption": "",
                "parent": 2954,
                "mime_type": "image/jpeg",

    },
   .....................

Parsing code

 static final String KEY_POSTS = "posts";
 static final String KEY_ID = "id";
 static final String KEY_SITEURL = "url";
static final String KEY_TITLE = "title";
static final String KEY_DATE = "date";
static final String KEY_CONTENT = "content";
static final String KEY_AUTHOR = "author";
static final String KEY_NAME = "name";
static final String KEY_ATTACHMENTS = "attachments";
static final String KEY_SLUG = "slug";
static final String KEY_THUMB_URL = "thumbnail";
static final String KEY_IMAGES = "images";
static final String KEY_URL = "url";

final  ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();


        // Creating JSON Parser instance
                final JSONParser jParser = new JSONParser();

                // getting JSON string from URL
                JSONObject json = jParser.getJSONFromUrl(URL);
                try {
                     posts = json.getJSONArray(KEY_POSTS);

        // looping through all song nodes <song>
                for(int i = 0; i < posts.length(); i++){
                    JSONObject c = posts.getJSONObject(i);

                    // Storing each json item in variable
                    String id = c.getString(KEY_ID);
                    String siteurl = c.getString(KEY_SITEURL);
                    String title = c.getString(KEY_TITLE);
                    String date = c.getString(KEY_DATE);
                    String content = c.getString(KEY_CONTENT);
                    // to remove all <P> </p> and <br /> and replace with ""
                     content = content.replace("<br />", "");
                     content = content.replace("<p>", "");
                     content = content.replace("</p>", "");

                    //authornumber is agin  JSON Object
                    JSONObject author = c.getJSONObject(KEY_AUTHOR);
                    String name = author.getString(KEY_NAME);

                    String url1 = null;
                    String slug1 = null;
                    try {
                    JSONArray atta = c.getJSONArray("attachments");
                    for(int j = 0; j < atta.length(); j++){
                        JSONObject d = atta.getJSONObject(j);

                        slug1 = d.getString(KEY_SLUG);

                        JSONObject images = d.getJSONObject(KEY_IMAGES);

                        JSONObject thumbnail = images.getJSONObject(KEY_THUMB_URL);
                        url1 = thumbnail.getString(KEY_URL);

                    }
                    } catch (Exception e) {
                        e.printStackTrace();

                    }




            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put(KEY_ID, id);
            map.put(KEY_TITLE, title);
            map.put(KEY_SITEURL, siteurl);
            map.put(KEY_DATE, date);
            map.put(KEY_NAME, name);
            map.put(KEY_CONTENT, content);
            map.put(KEY_SLUG, slug1);
            map.put(KEY_URL, url1);


            // adding HashList to ArrayList
            songsList.add(map);
                }   
                }catch (JSONException e) {
                    e.printStackTrace();

                    }



         final ListView  list=(ListView)findViewById(android.R.id.list);

         // Getting adapter by passing json data ArrayList
            adapter=new LazyAdapter(this, songsList);    
             list.setAdapter(adapter);

LazyAdapter.java

public class LazyAdapter extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}



public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_item, null);

    TextView title = (TextView)vi.findViewById(R.id.title); // title
    TextView siteurl = (TextView)vi.findViewById(R.id.siteurl);
    TextView date = (TextView)vi.findViewById(R.id.date); // artist name
    TextView content = (TextView)vi.findViewById(R.id.content);  // duration
    TextView name = (TextView)vi.findViewById(R.id.name); 
    // duration
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

    HashMap<String, String> song = new HashMap<String, String>();
    song = data.get(position);


    ListView list;
    // Setting all values in listview
   title.setText(song.get(MainActivity.KEY_TITLE));
   siteurl.setText(song.get(MainActivity.KEY_SITEURL));
    date.setText(song.get(MainActivity.KEY_DATE));
    content.setText(song.get(MainActivity.KEY_CONTENT));
    name.setText(song.get(MainActivity.KEY_NAME));

   imageLoader.DisplayImage(song.get(MainActivity.KEY_URL), thumb_image);
    return vi;
}

}

ImageLoader.java

         public class ImageLoader {
    MemoryCache memoryCache=new MemoryCache();
    FileCache fileCache;
    private Map<ImageView, String> imageViews=Collections.synchronizedMap(new     WeakHashMap<ImageView, String>());
    ExecutorService executorService; 

    public ImageLoader(Context context){
        fileCache=new FileCache(context);
        executorService=Executors.newFixedThreadPool(5);
    }

    final int stub_id = R.drawable.dollardesi;
    public void DisplayImage(String url, ImageView imageView)
    {
        imageViews.put(imageView, url);
        Bitmap bitmap=memoryCache.get(url);
        System.out.println("Image bitmap object from url*********$$$$$$$$"+bitmap);

        if(bitmap!=null)
            imageView.setImageBitmap(bitmap);
        else
        {
          System.out.println("In the else where there is null bitmap>>>>>>>>>");
            queuePhoto(url, imageView);
            imageView.setImageResource(stub_id);
        }
    }

    private void queuePhoto(String url, ImageView imageView)
    {
        PhotoToLoad p=new PhotoToLoad(url, imageView);
        executorService.submit(new PhotosLoader(p));
    }

    private Bitmap getBitmap(String url)
    {
        File f=fileCache.getFile(url);

        //from SD cache
        Bitmap b = decodeFile(f);
        if(b!=null)
            return b;

        //from web
        try {
            Bitmap bitmap=null;
            URL imageUrl = new URL(url);
            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
            conn.setConnectTimeout(30000);
            conn.setReadTimeout(30000);
            conn.setInstanceFollowRedirects(true);
            InputStream is=conn.getInputStream();
            OutputStream os = new FileOutputStream(f);
            Utils.CopyStream(is, os);
            os.close();
            bitmap = decodeFile(f);
            return bitmap;
        } catch (Exception ex){
           ex.printStackTrace();
           return null;
        }
    }

    //decodes image and scales it to reduce memory consumption
    private Bitmap decodeFile(File f){
        try {
            //decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f),null,o);

            //Find the correct scale value. It should be the power of 2.
            final int REQUIRED_SIZE=70;
            int width_tmp=o.outWidth, height_tmp=o.outHeight;
            int scale=1;
            while(true){
                if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
                    break;
                width_tmp/=2;
                height_tmp/=2;
                scale*=2;
            }

            //decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize=scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {}
        return null;
    }

    //Task for the queue
    private class PhotoToLoad
    {
        public String url;
        public ImageView imageView;
        public PhotoToLoad(String u, ImageView i){
            url=u;
            imageView=i;
        }
    }

    class PhotosLoader implements Runnable {
        PhotoToLoad photoToLoad;
        PhotosLoader(PhotoToLoad photoToLoad){
            this.photoToLoad=photoToLoad;
        }

        @Override
        public void run() {
            if(imageViewReused(photoToLoad))
                return;
            Bitmap bmp=getBitmap(photoToLoad.url);
            memoryCache.put(photoToLoad.url, bmp);
            if(imageViewReused(photoToLoad))
                return;
            BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad);
            Activity a=(Activity)photoToLoad.imageView.getContext();
            a.runOnUiThread(bd);
        }
    }

    boolean imageViewReused(PhotoToLoad photoToLoad){
        String tag=imageViews.get(photoToLoad.imageView);
        if(tag==null || !tag.equals(photoToLoad.url))
            return true;
        return false;
    }

    //Used to display bitmap in the UI thread
    class BitmapDisplayer implements Runnable
    {
        Bitmap bitmap;
        PhotoToLoad photoToLoad;
        public BitmapDisplayer(Bitmap b, PhotoToLoad p){bitmap=b;photoToLoad=p;}
        public void run()
        {
            if(imageViewReused(photoToLoad))
                return;
            if(bitmap!=null)
                photoToLoad.imageView.setImageBitmap(bitmap);
            else
                photoToLoad.imageView.setImageResource(stub_id);
        }
    }

    public void clearCache() {
        memoryCache.clear();
        fileCache.clear();
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:25:14+00:00Added an answer on June 18, 2026 at 4:25 am

    you are getting issue because both key is same for KEY_SITEURL and KEY_URL in HashMap so just change any one key to get it work as :

    static final String KEY_URL_FOR_MAP = "url_site";   //use this for adding 
                                                   //and retrivng value from Hashmap
    static final String KEY_URL = "url";   // use this for getting url JsonObject
    static final String KEY_SITEURL = "url";
    

    now use KEY_URL_FOR_MAP for adding url to Hashmap and to retrieve url form HashMap

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how do i display xml data using jquery? i don't need to parse it
I need to parse a protocol buffer send via a post using bottle. How
I need to parse the payload from different push notification, but if user press
I have a grid using jqgrid . I need to store the some data
I am getting some response from server side which i need to parse but
I have this requirement that I need to replace URL in CSS, so far
I have a done a project in which data like name, url, desc are
I have been using the plug in jquery.newsticker.js to display a newsticker that fades
I need to parse a FILE URL in my application, and replace the %20
i have to develop android listview using xml parsing., Am getting xml feed from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.