zoukankan      html  css  js  c++  java
  • MVC

    layout.activity_main);

    initViews();

    request();
    showDialog();
    }

    private void initViews() {
    tv = findViewById(R.id.tv);
    }

    private void showDialog() {
    ProgressDialog dialog = new ProgressDialog(this);
    dialog.show();
    new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
    dialog.dismiss();
    }
    }, 1500);
    }

    private void request() {
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder()
    .url("https://www.baidu.com/")
    .build();
    client.newCall(request).enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {
    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
    String resp = response.body().string();
    toast(resp);
    }
    });
    }

    private void toast(String resp) {
    runOnUiThread(new Runnable() {
    @Override
    public void run() {
    Toast.makeText(MainActivity.this, "" + resp, Toast.LENGTH_SHORT).show();
    tv.setText(resp);
    }
    });
    }

    }
    ---------------------

  • 相关阅读:
    python三元表达式
    购物车的升级系统
    python迭代器
    python函数装饰器
    python 闭包函数
    python名称空间与作用域
    python函数的嵌套
    python函数对象
    python函数之可变长参数
    python函数的参数
  • 原文地址:https://www.cnblogs.com/ly570/p/11342618.html
Copyright © 2011-2022 走看看