Странный код на java

By | June 3, 2015

http://developer.alexanderklimov.ru/android/theory/asynctask.php#newtask

http://metanit.com/java/tutorial/3.12.php

 

 

package ru.uber_remont.uber;

import android.app.Activity;
import android.os.AsyncTask;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;


import android.view.View;

import java.util.concurrent.TimeUnit;


public class Uber extends Activity  implements OnClickListener {





     CatTask cattask;
     TextView tvInfo;


    TextView tvOut;
    Button reg;
    Button search;
    Button about;
    Button inLogin;



    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uber);

        tvInfo = (TextView) findViewById(R.id.tvInfo);

        // найдем View-элементы
        reg = (Button) findViewById(R.id.reg);
        search = (Button) findViewById(R.id.search);
        about = (Button) findViewById(R.id.about);
        inLogin = (Button) findViewById(R.id.inLogin);


        reg.setOnClickListener(this);
        search.setOnClickListener(this);
        inLogin.setOnClickListener(this);
        about.setOnClickListener(this);



        // создание обработчика
        OnClickListener oclBtn = new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            }
        };
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_uber, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void onClick(View v){

        cattask = new CatTask();
        cattask.execute();


        switch (v.getId()) {
            case R.id.reg:
            {

                Intent intent = new Intent(Uber.this, Registration.class);
                startActivity(intent);
            }
            break;
            case R.id.inLogin:
            {
                Intent intent_login = new Intent(Uber.this, Login.class);
                startActivity(intent_login);
            }
            break;
            case R.id.about:
            {
                Intent intent_about = new Intent(Uber.this, A_about.class);
                startActivity(intent_about);
            }
            break;
        }
    }




    class CatTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            tvInfo.setText("Полез на крышу");
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            tvInfo.setText("Залез");
        }
    }
}

рабочий код потоков

Category: Uncategorized