2017-07-30 151 views
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 } 
 

 
}

回答

0

认沽下面的代码行下setContentView...

new Title().execute(); 
+0

其作品的兄弟.. THX ...并在同一时间执行多个AsynTaks像教程? http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/ –

+0

如果我的答案解决了您的问题,请接受它作为解决方案。 AsyncTask异步执行。如果您想同时调用多个AsyncTask,只需添加另一行,例如“new Description()。execute();”在您的新标题()... – James

+0

其因为我试图兄弟..但是,ProgressDialog永远不会停止加载 –

相关问题