1

I would like to show on the device's screen only this , without all the other unnecessary stuff , from this web page. This is my code so far...

package com.nextlogic.hellowebview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebView extends Activity {
    /** Called when the activity is first created. */
    WebView mWebView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://golfnews.no/nyheter.php?a=2013");
    }
}

Could you please help me ? It would be much appreciated. Thanks.

1 Answer 1

1

What you will need is a HTML Parser such as JSOUP. A great parser i use it for alot of projects.

This will allow you to parse only specific content,

Such as the image url from your webpage, and then retrieve it to a bitmap and set it to a imageview(Best to use an asynctask for this) and then you can use tags to retrieve the text.

Let me know if you need help with this.

EDIT: How to parse your Webpage with jsoup:

Document doc = Jsoup.parse("http://golfnews.no/nyheter.php?a=2013").get();
Elements article-text = doc.select(div.article);
//just to verify.
System.out.println(article-text.text());



TextView TextArticle = (TextView)findViewById(R.id.YOURTEXTVIEW);
TextArticle.setText(article-text.text());
//OR
String article = article-text.text();
TextArticle.setText(article);

Try this out.

EDIT: How to add external jar's

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

12 Comments

Using a webview is uneccessary in your situation. A parser is much more easier and cleaner.
I guess I would need a little bit of help , since I never used JSOUP before . Do you have a similar example that I could read and inspire from ? Thanks.
Yes i do. I can actually create an example for you here. I dont have a compiler so ill be writting the code from my head in the answer so if you copy and paste it into a compiler then correct it. It may be only be small errors if so..But first read this... jsoup.org/cookbook/extracting-data/selector-syntax and read alittle about jsoup in the link in the answer. Let me know when your done. This will give you a understanding of it.
Yes I read it . Could you give me the example ? It doesn't matter if it has some errors , I'll correct them in eclipse.
Ill comment when i am finished.
|

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.