AsyncTask

package com.example.administrator.mytest;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.TextView;

public class Main9Activity extends AppCompatActivity {
   private Button mBt1,mBt2;
    private ViewGroup viewGroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main9);
        mBt1= (Button) findViewById(R.id.bt_1);
        mBt2= (Button) findViewById(R.id.bt_2);

        TranslateAnimation animation=new TranslateAnimation(0,150,0,0);
        animation.setRepeatCount(30);
        animation.setDuration(2000);
        mBt1.setAnimation(animation);
       mBt2.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {

               new DownloadTask().execute();
           }
       });

    }
private class DownloadTask extends AsyncTask<String,Void,Integer>{
    @Override
    protected Integer doInBackground(String... params) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int sum=10;
        return sum;
    }
   protected void onPostExecute(Integer sum){
       mBt2.setText(""+sum);
   }
}


}
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/layout01"
    tools:context="com.example.administrator.mytest.Main9Activity">
<Button
    android:id="@+id/bt_1"
    android:layout_centerInParent="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="按钮1"
   />
    <Button
        android:id="@+id/bt_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮2"
        />
</RelativeLayout>

posted @ 2016-10-12 11:08  什么玩楞啊,我叫旺仔  阅读(166)  评论(0编辑  收藏  举报