public class MainActivity extends Activity
{
TextView text=null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text=(TextView)findViewById(R.id.text);
new Thread(){
public void run(){
try
{
String city=URLEncoder.encode("吉林");
URL url=new URL("http://apis.baidu.com/apistore/weatherservice/citylist?cityname="+city);
HttpURLConnection connect=(HttpURLConnection)url.openConnection();
connect.addRequestProperty("apikey","a26c0be1e453f588a7706d7e24fa87d1");
InputStream is= connect.getInputStream();
byte[] by=new byte[1024];
int a=is.read(by);
String str=new String(by,0,a);
text.setText(str);
}
catch (MalformedURLException e)
{}
catch (IOException e)
{}
};
}.start();
}
}
{
TextView text=null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text=(TextView)findViewById(R.id.text);
new Thread(){
public void run(){
try
{
String city=URLEncoder.encode("吉林");
URL url=new URL("http://apis.baidu.com/apistore/weatherservice/citylist?cityname="+city);
HttpURLConnection connect=(HttpURLConnection)url.openConnection();
connect.addRequestProperty("apikey","a26c0be1e453f588a7706d7e24fa87d1");
InputStream is= connect.getInputStream();
byte[] by=new byte[1024];
int a=is.read(by);
String str=new String(by,0,a);
text.setText(str);
}
catch (MalformedURLException e)
{}
catch (IOException e)
{}
};
}.start();
}
}