我正在尝试使用延迟图像加载器在我的Android应用程序中从服务器加载图像,但它不显示。通过JSON访问图像URL并传递给Lazy Loader仍然无法正常工作。请给出建议......
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
grid=(GridView)findViewById(R.id.gridView1);
testAsynch mytest= new testAsynch();
mytest.execute();
// adapter=new LazyAdapter(this,imgNames);
// grid.setAdapter(adapter);
adapter = new LazyAdapter(this, mylist);
grid.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
class testAsynch extends AsyncTask<Void,Integer,String>
{
String readFeed;
JSONObject json;
StringBuilder builder = new StringBuilder();
protected void onPreExecute(){
Log.d("PreExceute","On pre Exceute......");
}
protected String doInBackground(Void...arg0) {
Log.d("DoINBackGround","On doInBackground...");
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
// domain intentionally obfuscated for security reasons
HttpGet httpGet = new HttpGet("http://innobytes.in/webservices/category");
//HttpGet httpGet = new HttpGet("http://10.0.2.2/pratik/category");
httpGet.setHeader("content-type", "application/json; charset=UTF-8");
try
{
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.d("onProgressUpdate","Failed to download file..........");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
return builder.toString();
}
@SuppressWarnings("null")
protected void onPostExecute(String result) {
// NOTE: You can call UI Element here.
String autcElement = null;
String img;
//String url="http://innobytes.in/artsgallery.in/productpic/";
try{
readFeed = result;
JSONArray jsonarray = new JSONArray(readFeed);
System.out.println("OKAY_8!!");
//*********** Process each JSON Node ***********//*
int lengthJsonArr =jsonarray.length();
for (int i = 0; i < lengthJsonArr; i++)
{
System.out.println("OKAY_9!!");
autcElement = jsonarray.toString();
//name[i]=autcElement;
imgNames.add(autcElement);
// bean.setMediaImageUrl(jsonarray.toString());
mylist.add(autcElement);
}
System.out.print(""+imgNames);
}
catch (Exception e) {
e.printStackTrace();
}
// Close progress dialog
}
}}