android 实现模拟加载中的程序
生活随笔
收集整理的這篇文章主要介紹了
android 实现模拟加载中的程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
效果圖:
原始界面 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 點擊按鈕運行 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?運行后界面
? ? ??? ? ? ?
實現代碼:
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);
//顯示對話框
myDialog=ProgressDialog.show(MainActivity.this,strDialogTitle,strDialogBody,true);
tv.setText(R.string.result);
//創建一個空線程模擬運行
new Thread(){
public void run(){
try{
//設置線程睡眠3秒
sleep(3000);
}catch (Exception e){
e.printStackTrace();
}
finally {
//刪除所創建的myDialog對象
myDialog.dismiss();
}
}
}.start();//開始運行線程
}
}
}
?
轉載于:https://www.cnblogs.com/xy95/p/5861421.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的android 实现模拟加载中的程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多态、虚方法、重写
- 下一篇: webStorm Linux Ubunt