Skip to content

Instantly share code, notes, and snippets.

@kakawka
Created July 11, 2014 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakawka/067595c290a72ad782ca to your computer and use it in GitHub Desktop.
Save kakawka/067595c290a72ad782ca to your computer and use it in GitHub Desktop.
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button butTest;
TextView textView;
String title;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
butTest = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textView);
new MyParser().execute("http://beastinvest.su/");
butTest.setOnClickListener(butOncl);
}
private View.OnClickListener butOncl = new View.OnClickListener() {
public void onClick(View v) {
onPostExecute(title);
}
};
public class MyParser extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... links) {
Document doc = null;
try {
doc = Jsoup.connect(links[0]).get();
title = doc.title();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
public void onPostExecute(String result) {
textView.setText(title);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment