English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Recently, I did nothing but make an Android mini-program, as follows:
Effect picture:
Original interface
Click the button to run
Interface after running
Implementation code:
public class MainActivity extends AppCompatActivity { private Button bt; private TextView tv; public ProgressDialog myDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt = (Button) findViewById(R.id.button); tv = (TextView) findViewById(R.id.text); bt.setOnClickListener(new myOnClickListener()); } private class myOnClickListener implements View.OnClickListener{ @Override public void onClick(View v) { final CharSequence strDialogTitle=getString(R.string.app_about); final CharSequence strDialogBody=getString(R.string.app_msg); //Display dialog myDialog=ProgressDialog.show(MainActivity.this,strDialogTitle,strDialogBody,true); tv.setText(R.string.result); //Create an empty thread to simulate running new Thread(){ public void run(){ try{ //Set thread sleep3seconds sleep(3000); }catch (Exception e){ e.printStackTrace(); } finally { //Delete the myDialog object created myDialog.dismiss(); } } }.start();//Start running the thread } } }
That's all for this article. I hope it will be helpful to everyone's learning and that everyone will support the Shouting Tutorial more.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)