使用此功能以列表,图库,网格视图的形式集成图像显示
https://github.com/nostra13/Android-Universal-Image-Loader
但必须将来自服务器的图像一张一张地整合在一起..请建议我..请给我示例。
public class ParsingActivity extends Activity {
ParsingPojo data_pojo;
ArrayList<ParsingPojo> dataArray;
ListView diagnoList;
ImageView dataWithImage;
private EditText editTextInput;
ProgressDialog mdialog;
ProgressDialog progressDialog;
private Handler handler;
private Handler messageHandler;
private ProgressDialog progress;
private Context context;
String resp, url;
protected DisplayImageOptions displayImage;
protected ImageLoader imageLoader = ImageLoader.getInstance();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cat);
dataWithImage = (ImageView) findViewById(R.id.stack);
displayImage = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_launcher)
.showStubImage(R.drawable.ic_launcher)
.cacheInMemory()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
imageLoader.init(ImageLoaderConfiguration
.createDefault(ParsingActivity.this));
new Task().execute();
}
protected void search() {
// TODO Auto-generated method stub
}
static class ViewHolder {
TextView coverTitle, content, image;
ImageView images;
}
class Task extends AsyncTask<Void, Void, Void> {
ProgressDialog pd;
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd = ProgressDialog.show(ParsingActivity.this, "please wait..",
"loading data");
}
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
try {
url = "your url";
resp = CustomHttpClient.executeHttpGet(url);
dataArray = new ArrayList<ParsingPojo>();
JSONArray data = new JSONArray(resp);
for (int i = 0; i < data.length(); i++) {
data_pojo = new ParsingPojo();
JSONObject jobj = data.getJSONObject(i);
JSONObject innerObject = jobj.getJSONObject("first_post");
JSONArray imageArray = innerObject.getJSONArray("files");
JSONArray imageOk = imageArray.getJSONArray(0);
data_pojo.setImage("ur url"
+ imageOk.getString(0));
data_pojo.setContent(innerObject.getString("content"));
data_pojo.setConv_title(jobj.getString("conv_title"));
dataArray.add(data_pojo);
}
/*
* JSONObject jobj = new JSONObject(resp); JSONArray jarray =
* jobj.getJSONArray("diagnoresultpojo"); // JSONArray jarray =
* new JSONArray("diagnoresultpojo");
*
* dataArray = new ArrayList<ParsingPojo>(); for (int i = 0; i <
* jarray.length(); i++) { data_pojo = new ParsingPojo();
* JSONObject insideArrayJobj = jarray.getJSONObject(i);
* data_pojo.setName(insideArrayJobj.getString("name"));
* data_pojo.setMobile(insideArrayJobj.getString("mobile"));
* data_pojo.setImage_url(insideArrayJobj
* .getString("image_url"));
* data_pojo.setEmail(insideArrayJobj.getString("email"));
* data_pojo.setAddress(insideArrayJobj.getString("address"));
* dataArray.add(data_pojo); } Log.d("array size",
* dataArray.size() + "");
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pd.dismiss();
if (dataArray != null) {
dataWithImage.setAdapter(new Adapter());
}
}
}
public class Adapter extends BaseAdapter {
public int getCount() {
// TODO Auto-generated method stub
if (dataArray.size() != 0) {
return dataArray.size();
} else
return 0;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
View show = arg1;
ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (show == null) {
holder = new ViewHolder();
show = inflater.inflate(R.layout.gallery_image, null);
holder.coverTitle = (TextView) show.findViewById(R.id.name);
// holder.content = (TextView) show.findViewById(R.id.content);
// holder.image = (TextView) show.findViewById(R.id.image);
holder.images = (ImageView) show.findViewById(R.id.image);
/*
* holder.mobile = (TextView) show.findViewById(R.id.mobile);
* holder.email = (TextView) show.findViewById(R.id.email);
* holder.address = (TextView) show.findViewById(R.id.address);
* holder.image = (TextView) show.findViewById(R.id.image);
*/
} else {
holder = (ViewHolder) show.getTag();
}
holder.coverTitle.setText(dataArray.get(arg0).getConv_title());
// holder.content.setText(dataArray.get(arg0).getContent());
// holder.image.setText(dataArray.get(arg0).getImage());
imageLoader.displayImage(dataArray.get(arg0).getImage(),
holder.images, displayImage);
holder.images.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent content = new Intent(ParsingActivity.this,
Content.class);
content.putExtra("data", dataArray.get(arg0).getContent());
content.putExtra("title", dataArray.get(arg0)
.getConv_title());
startActivity(content);
}
});
/*
* holder.mobile.setText(dataArray.get(arg0).getMobile());
* holder.email.setText(dataArray.get(arg0).getEmail());
* holder.address.setText(dataArray.get(arg0).getAddress());
* holder.image.setText(dataArray.get(arg0).getImage_url());
*/
show.setTag(holder);
return show;
}
}
}