0
我想在不按按鈕的情況下直接顯示此內容。有人能幫我嗎?我是編程界的新手。如何在不按按鈕的情況下顯示此內容?
在下面有完整的內容,如果你想分析更好。直接
http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/
public class MainActivity extends Activity {
\t // URL Address
\t String url = "http://www.androidbegin.com";
\t ProgressDialog mProgressDialog;
\t @Override
\t public void onCreate(Bundle savedInstanceState) {
\t \t super.onCreate(savedInstanceState);
\t \t setContentView(R.layout.activity_main);
\t \t // Locate the Buttons in activity_main.xml
\t \t Button titlebutton = (Button) findViewById(R.id.titlebutton);
\t \t
\t \t // Capture button click
\t \t titlebutton.setOnClickListener(new OnClickListener() {
\t \t \t public void onClick(View arg0) {
\t \t \t \t // Execute Title AsyncTask
\t \t \t \t new Title().execute();
\t \t \t }
\t \t });
\t }
\t // Title AsyncTask
\t private class Title extends AsyncTask<Void, Void, Void> {
\t \t String title;
\t \t @Override
\t \t protected void onPreExecute() {
\t \t \t super.onPreExecute();
\t \t \t
\t \t }
\t \t @Override
\t \t protected Void doInBackground(Void... params) {
\t \t \t try {
\t \t \t \t // Connect to the web site
\t \t \t \t Document document = Jsoup.connect(url).get();
\t \t \t \t // Get the html document title
\t \t \t \t title = document.title();
\t \t \t } catch (IOException e) {
\t \t \t \t e.printStackTrace();
\t \t \t }
\t \t \t return null;
\t \t }
\t \t @Override
\t \t protected void onPostExecute(Void result) {
\t \t \t // Set title into TextView
\t \t \t TextView txttitle = (TextView) findViewById(R.id.titletxt);
\t \t \t txttitle.setText(title);
\t \t \t mProgressDialog.dismiss();
\t \t }
\t }
}
其作品的兄弟.. THX ...並在同一時間執行多個AsynTaks像教程? http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/ –
如果我的答案解決了您的問題,請接受它作爲解決方案。 AsyncTask異步執行。如果您想同時調用多個AsyncTask,只需添加另一行,例如「new Description()。execute();」在您的新標題()... – James
其因爲我試圖兄弟..但是,ProgressDialog永遠不會停止加載 –