AsycTask------MainActivity

来源:互联网 发布:帝国cms视频教程 编辑:程序博客网 时间:2024/05/21 02:36
package com.rong.day08_asynctask;import java.util.concurrent.ExecutionException;import com.bawei.asyctask.MyAsycTask;import android.os.Bundle;import android.app.Activity;import android.util.Log;import android.view.Menu;import android.widget.TextView;public class MainActivity extends Activity {String key = "3ac9f31ff66b9746539472887b3799c3";// 通过get请求时的接口地址String get_path = "http://web.juhe.cn:8080/constellation/getAll?consName=狮子座&type=today&key="+ key;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TextView tv = (TextView) findViewById(R.id.tv);MyAsycTask myAsycTask = new MyAsycTask(tv);try {String string = myAsycTask.execute(get_path).get();Log.d("lcr", string);//tv.setText(string);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ExecutionException e) {// TODO Auto-generated catch blocke.printStackTrace();}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

0 0
原创粉丝点击