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;
@Override
protected 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 block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public 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;
}
}
AsycTask------MainActivity
最新推荐文章于 2023-09-30 12:12:25 发布