Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.jsoup1;
- import java.io.IOException;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- String url = "http://dantri.com.vn/chuyen-la.rss";
- ProgressDialog dialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button btten = (Button) findViewById(R.id.btten);
- btten.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- new Title().execute();
- }
- });
- }
- public class Title extends AsyncTask<Void, Void, Void> {
- String title;
- @Override
- protected Void doInBackground(Void... params) {
- // TODO Auto-generated method stub
- try {
- Document document = Jsoup.connect(url).get();
- title = document.title();
- } catch (IOException e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return null;
- }
- @Override
- protected void onPostExecute(Void result) {
- // TODO Auto-generated method stub
- TextView tv = (TextView)findViewById(R.id.tvten);
- tv.setText(title);
- dialog.dismiss();
- // super.onPostExecute(result);
- }
- @Override
- protected void onPreExecute() {
- // TODO Auto-generated method stub
- super.onPreExecute();
- dialog = new ProgressDialog(MainActivity.this);
- dialog.setTitle("Hoang Anh");
- dialog.setMessage("Loading... ");
- dialog.setIndeterminate(false);
- dialog.show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement