• .模拟文件拷贝:


    package com.hanqi.testapp22;
    
            import android.app.ProgressDialog;
            import android.os.Bundle;
            import android.os.Message;
            import android.support.v7.app.AppCompatActivity;
            import android.view.View;
            import android.widget.TextView;
            import android.widget.Toast;
    
            import android.os.Handler;
    
    public class lianxiActivity extends AppCompatActivity {
        TextView tv_2;
        Handler h =new Handler()
        {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg.what == 1) {
                    String m = msg.obj.toString();
                    tv_2.setText(tv_2.getText() + "" + m);
                }
            }
        };
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_lianxi);
            tv_2=(TextView)findViewById(R.id.tv_2);
    
        }
        public void bt1_OnClick(View v)
        {
            final ProgressDialog progressDialog=new ProgressDialog(this);
            progressDialog.setTitle("拷贝进度");
            progressDialog.setMessage("拷贝中...");
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.show();
            final TextView tv_1=(TextView)findViewById(R.id.tv_1);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i=1;i<=100;i++)
                    {
                        progressDialog.setProgress(i);
                        try {
                            Thread.sleep(200);
                        }catch (Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
    
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            tv_1.setText("拷贝完成");
                        }
                    });
                    progressDialog.dismiss();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(lianxiActivity.this, "拷贝完成", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }).start();
        }
        public void bt2_OnClick(View v)
        {
            final ProgressDialog p=new ProgressDialog(this);
            p.setTitle("拷贝进度");
            p.setMessage("拷贝中...");
            p.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            p.show();
    
            new Thread(){
                @Override
                public void run() {
                    for (int i=1;i<=100;i++)
                    {
                        p.setProgress(i);
                        try {
                            Thread.sleep(200);
                        }catch (Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
    
                    p.dismiss();
                    Message m =Message.obtain();
                    m.what=1;
                    m.obj="拷贝完成";
                    h.sendMessage(m);
    
                }
            }.start();
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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="com.hanqi.testapp22.lianxiActivity"
        android:orientation="vertical">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt_1"
            android:onClick="bt1_OnClick"
            android:text="水平进度对话框和子线程模拟拷贝进度"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tv_1"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt_2"
            android:onClick="bt2_OnClick"
            android:text="水平进度对话框和子线程模拟拷贝进度"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tv_2"/>
    
    </LinearLayout>
    View Code

  • 相关阅读:
    移动端开发常见的坑
    javascript的原始类型(primitive type)之间的关系。
    微信小程序学习:开发注意点
    canvas学习(一):线条,图像变换和状态保存
    css模仿微信弹出菜单
    html5 canvas绘制环形进度条,环形渐变色仪表图
    vue学习笔记(三):vue-cli脚手架搭建
    nodejs基础学习
    css3美化radio样式
    基于angular+bower+glup的webapp
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5504657.html
Copyright © 2020-2023  润新知