ImageView在android min sdk 2.2上工作,但在我改为3.0时不工作?
我正在制作一个使用互联网数据的android应用程序。我在min sdk版本2.2上开发,但现在我将其更改为3.0。我的问题是,现在有些组件不工作。我猜2.2版中的一些代码在3.0版中可能会被弃用。但我不知道该怎么做才能让它工作 例如,我的ImageView在2.2中工作。但在3.0中,情况并非如此ImageView在android min sdk 2.2上工作,但在我改为3.0时不工作?,android,json,android-compatibility,android-version,loadimage,Android,Json,Android Compatibility,Android Version,Loadimage,我正在制作一个使用互联网数据的android应用程序。我在min sdk版本2.2上开发,但现在我将其更改为3.0。我的问题是,现在有些组件不工作。我猜2.2版中的一些代码在3.0版中可能会被弃用。但我不知道该怎么做才能让它工作 例如,我的ImageView在2.2中工作。但在3.0中,情况并非如此 //******satellite url private void satellite() { // TODO Auto-generated met
//******satellite url
private void satellite() {
// TODO Auto-generated method stub
ImageView imgView =(ImageView)findViewById(R.id.satellite);
Drawable drawable = LoadImageFromWeb("http://www.pagasa.dost.gov.ph/wb/sat_images/satellite.gif");
imgView.setImageDrawable(drawable);
}
另一个是我的json解析器。它在2.2中也能完美工作,但在3.0中却不能
//json stuffs , setText on textViews in main menu
private void jsonStuffs() {
// TODO Auto-generated method stub
//JSON PARSER & HOME PAGE TEXTVIEWS
client = new DefaultHttpClient();
//new Read().execute("id");
//http client codes only no parser !!
GetMethodEx test = new GetMethodEx();
String returned;
try {
returned = test.getInternetData();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
String jsonStr = test.getInternetData(); //punta sa GetMethodEx
JSONObject obj = new JSONObject(jsonStr);
//find temperature sa JSON sa webpage
String temperature = obj.getString("temperature");
TextView tvTemp = (TextView)findViewById(R.id.temp);
tvTemp.setText(temperature);
//find sunrise sa JSON sa webpage
String sunrise = obj.getString("sunrise");
TextView tvSunrise = (TextView)findViewById(R.id.sunrise);
tvSunrise.setText("Sunrise: " + sunrise);
//find sunset sa JSON sa webpage
String sunset = obj.getString("sunset");
TextView tvSunset = (TextView)findViewById(R.id.sunset);
tvSunset.setText("Sunset: " + sunset);
}
//catch (JSONException e) {
// e.printStackTrace();
//}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我在这个项目上没有收到任何错误。只是数据没有显示,imageview没有显示等等
我希望有人能帮忙。提前感谢:)我认为原因是Android 3.0及以上版本,您需要在单独的线程中执行网络操作,如http请求和所有,然后是UI线程。您直接在UI线程中使用代码,因此它在HoneyComb下工作。因此,您需要将web请求放在单独的线程中,然后放在UI中<代码>异步任务是一个不错的选择
要了解更多详细信息,我认为原因是Android 3.0及以上版本,您需要在单独的线程中执行网络操作,如http请求,然后是UI线程。您直接在UI线程中使用代码,因此它在HoneyComb下工作。因此,您需要将web请求放在单独的线程中,然后放在UI中<代码>异步任务是一个不错的选择
有关更多详细信息谢谢!我想这就是原因。我试试另一条线。谢谢!我想这就是原因。我试试另一条线。