AsyncTask

来源:互联网 发布:无线传感器网络 编辑:程序博客网 时间:2024/06/11 21:59

    private ListView lv;    /**     * ATTENTION: This was auto-generated to implement the App Indexing API.     * See https://g.co/AppIndexing/AndroidStudio for more information.     */    private String path;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        lv = (ListView) findViewById(R.id.one_lv);        if (isNetworkAvailable(this)) {            Woulsp wluoSp = new Woulsp(this);            path = "http://v3.wufazhuce.com:8000/api/reading/index/?version=3.5.0&platform=android";            wluoSp.execute(path, lv);        } else {            //无网络时显示另一个套路            List list = new ArrayList<>();            list.add("网络超时");            ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list);            lv.setAdapter(adapter);        }    }    public static boolean isNetworkAvailable(Context context) {        ConnectivityManager connectivity = (ConnectivityManager) context                .getSystemService(Context.CONNECTIVITY_SERVICE);        if (connectivity != null) {            NetworkInfo info = connectivity.getActiveNetworkInfo();            if (info != null && info.isConnected()) {                // 当前网络是连接的                if (info.getState() == NetworkInfo.State.CONNECTED) {                    // 当前所连接的网络可用                    return true;                }            }        }        return false;    }

0 0
原创粉丝点击