1

I have one parameter in json data called "content" from which I want to get image urls and display that images in ImageView dynamically.

I have tried Pattern and Matcher classes and I am getting firstimage url correctly but could not able to make out logic for more than one image url.

content is as follows:

"content":"<p style=\"text-align: justify;\">Huawei India has expanded the reach and availability of their online-only Honor smartphone series.<img class=\"aligncenter size-full wp-image-14114\" src=\"http:\/\/imageurl.jpg\"\/><p style=\"text-align: justify;\">Huawei India, along with it, has also confirmed that Honor smartphones will get the Android 6.0 Marshmallow updates with other devices in the upcoming year in the month of February.<\/p><img class=\"aligncenter size-full wp-image-14115\" src=\"http:\/\/second Image url.png\" \/>\n<p style=\"text-align: justify;\">The new update is likely to get Huawei Honor users to be excited, if you are a Honor smartphone user do share your feelings in the comment box below.<\/p>\n"

I am getting first image url as follows:

String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
        Pattern p = Pattern.compile(imgRegex);
        Matcher m = p.matcher(posts.getExcerpt());
        String src = "";
        if (m.find()) {
            src = m.group(1);
            imgPost.setVisibility(View.VISIBLE);
            Log.v("groupCount : ",""+m.groupCount());
            //Toast.makeText(this,"pattern : "+src,Toast.LENGTH_LONG).show();
            Picasso.with(this)
                    .load(""+src)
                    .error(R.drawable.ic_launcher)
                    .into(imgPost);
        }

Any idea how to get all image urls using PatternMatcher class or anything else??

1
  • 1
    try this: JSoup in android Commented Jan 19, 2016 at 8:12

2 Answers 2

1

It seems to me that once you get the json string the content in HTML. You could use JSoup to extract data it is very easy.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use while( m.find()){ ... } instead of the conditional

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.