按下更新按钮,每隔1S自动更新进度条,更新到100%自动消失
来源:互联网 发布:通讯录软件 编辑:程序博客网 时间:2024/06/14 11:44
按下更新按钮,每隔1S自动更新进度条,更新到100%自动消失
activity:
package com.example.trd;
import android.os.Bundle;import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
Button btn=null;
private ProgressBar pb=null;
private int progress=0;
Handler h=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.button1);
pb=(ProgressBar)findViewById(R.id.bar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void hhhhh(View v){
MyThread t=new MyThread();
t.start();
}
class MyThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
while(progress<pb.getMax()){
progress+=10;
pb.setProgress(progress);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO: handle exception
e.printStackTrace();
}
if(progress>=pb.getMax())
h.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
pb.setVisibility(View.GONE);
}
});
}
}
}
}
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:layout_marginBottom="181dp"
android:text="更新ing"
android:onClick="hhhhh"/>
<ProgressBar
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:layout_below="@id/button1"
android:max="100"
/>
</RelativeLayout>
- 按下更新按钮,每隔1S自动更新进度条,更新到100%自动消失
- 每隔10秒自动更新svn 定时更新svn 脚本
- ProgressDialog 更新完后自动消失
- 更新进度条
- 带进度条自动下载更新升级组件
- Easyui_Datagrid更新行数据后,行按钮消失简单解决办法
- android版本自动检测更新 版本检测 自动更新 自动安装
- 更新到WordPress 3.1后Custom Fields消失?
- 更新器自动更新自己(自我更新)
- android,检查更新,版本更新,自动更新
- 让AIR程序自动检测更新,自动下载更新到新版本
- umeng自动更新之强制更新
- Android初试--更新进度条(ProgressBar)1
- 下载任务中更新进度条要到主线程中
- Android更新下载进度条
- Android更新下载进度条
- Android更新下载进度条
- Handler更新进度条
- C# DateTime和TimeSpan
- android依赖库(依赖工程)导入
- Mint17双屏分辨率设置
- 每个类有很多方法,每个对象的类型不同
- Looper的实现原理
- 按下更新按钮,每隔1S自动更新进度条,更新到100%自动消失
- inet_ntoa函数陷阱
- 如何找到真机调试让手机信任应用程序的步骤
- Python导入mysql
- MySQL常用命令
- redhat 6.5 安装 codeblock 13.12
- Codeforces 638A Home Numbers 【水题】
- 链表计算多项式的和,乘积
- 韩信点兵【nyoj34】