radityakurnianto

HelloParsing.java

Jun 7th, 2013
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. package com.helloparsing;
  2.  
  3. import android.os.Bundle;
  4. import android.annotation.SuppressLint;
  5. import android.app.Activity;
  6. import android.view.*;
  7. import android.widget.*;
  8. import android.content.*;
  9. import org.jsoup.Jsoup;
  10. import org.jsoup.nodes.Document;
  11. import org.jsoup.select.Elements;
  12.  
  13. public class HelloParsing extends Activity {
  14.     Button parse;
  15.     TextView date, bible, title, body;
  16.     Document doc;
  17.     Elements dates, bibles, titles, bodies;
  18.     String tanggal, ayat, judul, isi;
  19.     private ShareActionProvider mShareActionProvider;
  20.    
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.activity_hello_parsing);
  25.         parse = (Button)findViewById(R.id.parse);
  26.         date = (TextView)findViewById(R.id.date);
  27.         bible = (TextView)findViewById(R.id.bible);
  28.         title = (TextView)findViewById(R.id.title);
  29.         body = (TextView)findViewById(R.id.body);
  30.        
  31.         parse.setOnClickListener(new View.OnClickListener()
  32.         {
  33.             @Override
  34.             public void onClick(View v)
  35.             {
  36.                 try
  37.                 {
  38.                     doc = Jsoup.connect("http://sabda.org/publikasi/e-rh/2013/03/30/").get();
  39.                     bodies = doc.getElementsByTag("p");
  40.                    
  41.                     isi = bodies.text();
  42.                     body.setText(isi);
  43.                 }
  44.                  catch(Exception ex)
  45.                 {
  46.                       Toast.makeText(getApplicationContext(), "Failed \n" + ex, Toast.LENGTH_LONG).show();
  47.                 }
  48.             }
  49.         });
  50.        
  51.        
  52.     }
  53.  
  54.     @SuppressLint("NewApi")
  55.     @Override
  56.     public boolean onCreateOptionsMenu(Menu menu) {
  57.         // Inflate the menu; this adds items to the action bar if it is present.
  58.         getMenuInflater().inflate(R.menu.hello_parsing, menu);
  59.         MenuItem item = menu.findItem(R.id.menu_item_share);
  60.         mShareActionProvider = (ShareActionProvider)item.getActionProvider();
  61.         return true;
  62.     }
  63.    
  64.     @SuppressWarnings("unused")
  65.     private void setShareIntent(Intent shareIntent)
  66.     {
  67.         if(mShareActionProvider != null)
  68.         {
  69.             mShareActionProvider.setShareIntent(shareIntent);
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment