Advertisement
anhit92

HAHA

Jun 29th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package com.example.jsoup1;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.jsoup.Jsoup;
  6. import org.jsoup.nodes.Document;
  7.  
  8. import android.app.Activity;
  9. import android.app.ProgressDialog;
  10. import android.os.AsyncTask;
  11. import android.os.Bundle;
  12. import android.view.View;
  13. import android.view.View.OnClickListener;
  14. import android.widget.Button;
  15. import android.widget.TextView;
  16.  
  17. public class MainActivity extends Activity {
  18.     String url = "http://dantri.com.vn/chuyen-la.rss";
  19.     ProgressDialog dialog;
  20.  
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.activity_main);
  25.         Button btten = (Button) findViewById(R.id.btten);
  26.         btten.setOnClickListener(new OnClickListener() {
  27.  
  28.             @Override
  29.             public void onClick(View arg0) {
  30.                 // TODO Auto-generated method stub
  31.                 new Title().execute();
  32.             }
  33.         });
  34.     }
  35.  
  36.     public class Title extends AsyncTask<Void, Void, Void> {
  37.         String title;
  38.         @Override
  39.         protected Void doInBackground(Void... params) {
  40.             // TODO Auto-generated method stub
  41.             try {
  42.                 Document document = Jsoup.connect(url).get();
  43.                 title = document.title();
  44.             } catch (IOException e) {
  45.                 // TODO: handle exception
  46.                 e.printStackTrace();
  47.             }
  48.             return null;
  49.         }
  50.  
  51.         @Override
  52.         protected void onPostExecute(Void result) {
  53.             // TODO Auto-generated method stub
  54.             TextView tv = (TextView)findViewById(R.id.tvten);
  55.             tv.setText(title);
  56.             dialog.dismiss();
  57. //          super.onPostExecute(result);
  58.         }
  59.  
  60.         @Override
  61.         protected void onPreExecute() {
  62.             // TODO Auto-generated method stub
  63.             super.onPreExecute();
  64.             dialog = new ProgressDialog(MainActivity.this);
  65.             dialog.setTitle("Hoang Anh");
  66.             dialog.setMessage("Loading... ");
  67.             dialog.setIndeterminate(false);
  68.             dialog.show();
  69.         }
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement