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.

Teo
  • 3,246
  • 9
  • 37
  • 70

1 Answers1

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

Community
  • 1
  • 1
coder_For_Life22
  • 24,973
  • 20
  • 82
  • 117
  • Using a webview is uneccessary in your situation. A parser is much more easier and cleaner. – coder_For_Life22 Sep 29 '11 at 13:01
  • 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. – Teo Sep 29 '11 at 13:10
  • 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... http://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. – coder_For_Life22 Sep 29 '11 at 13:12
  • 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. – Teo Sep 29 '11 at 13:23
  • Ill comment when i am finished. – coder_For_Life22 Sep 29 '11 at 13:32
  • Try out the code ive posted above. Dont forget to download and include the jsoup jar from the website in my answer. – coder_For_Life22 Sep 29 '11 at 13:43
  • div.article should be "div.article" in quotations. – coder_For_Life22 Sep 29 '11 at 13:49
  • This may sound stupid . Where do I put jsoup-1.6.1.jar after I've downloaded it ? – Teo Sep 29 '11 at 13:54
  • =) we all begin some where. Check my edit with a link to show you how. – coder_For_Life22 Sep 29 '11 at 14:02
  • It gives me an error at .get() -> "..is undefined for this type " and if I delete it , the application crashes. – Teo Sep 30 '11 at 11:43
  • What if I have a video on that page ? Woul Jsoup parser still do the job and take the video also from the page? – Teo Sep 30 '11 at 13:39
  • No it can just take the url of the video. – coder_For_Life22 Sep 30 '11 at 20:21