简体   繁体   English

如何在不按按钮的情况下显示此内容?

[英]How to show this content without press the button?

I would like to show direct this content without press the buttons. 我想直接显示此内容,而无需按按钮。 Can someone help me? 有人能帮我吗? I'm new to the programming world. 我是编程世界的新手。

In the below have the complete content, if you want to analyze better. 如果您想更好地分析,则在下面有完整的内容。

http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/ http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/

 public class MainActivity extends Activity { // URL Address String url = "http://www.androidbegin.com"; ProgressDialog mProgressDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Locate the Buttons in activity_main.xml Button titlebutton = (Button) findViewById(R.id.titlebutton); // Capture button click titlebutton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // Execute Title AsyncTask new Title().execute(); } }); } // Title AsyncTask private class Title extends AsyncTask<Void, Void, Void> { String title; @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBackground(Void... params) { try { // Connect to the web site Document document = Jsoup.connect(url).get(); // Get the html document title title = document.title(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { // Set title into TextView TextView txttitle = (TextView) findViewById(R.id.titletxt); txttitle.setText(title); mProgressDialog.dismiss(); } } } 

将以下代码直接放在setContentView...行下

new Title().execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM