求解!!!急!!!
package com.cnyckj.activity;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.GridView;
import com.cnyckj.adapter.PSGridViewAdapter;
public class PhotoThumbnailActivity extends Activity {
PSGridViewAdapter psgva;
ProgressDialog proDialog;//转圈圈
List<String> list = new ArrayList<String>();
GridView gv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_thumbnail);//设置布局文件
//获取
gv = (GridView)findViewById(R.id.gvPTGrid);
//提示等待
// proDialog = ProgressDialog.show(PhotoThumbnailActivity.this, PhotoThumbnailActivity.this.getString(R.string.ple_waite_title), PhotoThumbnailActivity.this.getString(R.string.ple_nowLoad),true);
list.add("http://192.168.1.114:8080/webdav/e.jpg");
list.add("http://192.168.1.114:8080/webdav/w.png");
list.add("http://192.168.1.114:8080/webdav/r.png");
list.add("http://192.168.1.114:8080/webdav/t.png");
list.add("http://192.168.1.114:8080/webdav/y.png");
list.add("http://192.168.1.114:8080/webdav/b.jpg");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/r.png");
list.add("http://192.168.1.114:8080/webdav/t.png");
list.add("http://192.168.1.114:8080/webdav/f.jpg");
list.add("http://192.168.1.114:8080/webdav/g.jpg");
list.add("http://192.168.1.114:8080/webdav/y.png");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/c.jpg");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/e.jpg");
list.add("http://192.168.1.114:8080/webdav/b.jpg");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/e.jpg");
list.add("http://192.168.1.114:8080/webdav/w.png");
list.add("http://192.168.1.114:8080/webdav/r.png");
list.add("http://192.168.1.114:8080/webdav/t.png");
list.add("http://192.168.1.114:8080/webdav/y.png");
list.add("http://192.168.1.114:8080/webdav/b.jpg");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/r.png");
list.add("http://192.168.1.114:8080/webdav/t.png");
list.add("http://192.168.1.114:8080/webdav/f.jpg");
list.add("http://192.168.1.114:8080/webdav/g.jpg");
list.add("http://192.168.1.114:8080/webdav/y.png");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/c.jpg");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/e.jpg");
list.add("http://192.168.1.114:8080/webdav/b.jpg");
list.add("http://192.168.1.114:8080/webdav/u.png");
list.add("http://192.168.1.114:8080/webdav/e.jpg");
list.add("http://192.168.1.114:8080/webdav/w.png");
list.add("http://192.168.1.114:8080/webdav/r.png");
list.add("http://192.168.1.114:8080/webdav/t.png");
list.add("http://192.168.1.114:8080/webdav/y.png");
list.add("http://192.168.1.114:8080/webdav/b.jpg");
psgva = new PSGridViewAdapter(PhotoThumbnailActivity.this, list);
gv.setAdapter(psgva);
}
}
package com.cnyckj.adapter;
import java.util.List;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.cnyckj.activity.PhotoThumbnailActivity;
import com.cnyckj.activity.R;
import com.cnyckj.asyncload.AsyncImageLoad;
import com.cnyckj.asyncload.AsyncImageLoad.ImageCallback;
public class PSGridViewAdapter extends BaseAdapter {
private List<String> ls;
private AsyncImageLoad asyncImageLoad;
private LayoutInflater li;
private Context con;
public PSGridViewAdapter(Context context,List<String> listStr){
li = LayoutInflater.from(context);
ls = listStr;
con = context;
asyncImageLoad = new AsyncImageLoad();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return ls.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return ls.get(position);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
return super.getItemViewType(position);
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return super.getViewTypeCount();
}
@Override
public View getView(int position, View view, ViewGroup arg2) {
AsyncImageLoad imageLoader = new AsyncImageLoad();
final ImageView image;
Log.i("reader", position+"____");
if(view==null){
Log.i("reader", "new");
view = li.inflate(R.layout.show_one_photo, null);
image = (ImageView)view.findViewById(R.id.imgPTShowPhoto);
String imgUrl = ls.get(position);//获取当前url
//异步加载图片,实现回调接口
Drawable drawable = imageLoader.loadDrawable(imgUrl, new ImageCallback() {
@Override
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
image.setImageDrawable(imageDrawable);//设置图片
}
});
if(drawable==null){
image.setImageResource(R.drawable.logo);
}
}else{
Log.i("reader", "old");
image = (ImageView)view.getTag();
}
view.setTag(image);
return view;
}
}
package com.cnyckj.asyncload;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import com.cnyckj.activity.PhotoThumbnailActivity;
import com.cnyckj.http.methods.Get;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class AsyncImageLoad {
private HashMap<String, SoftReference<Drawable>> imageCache;
public AsyncImageLoad() {
imageCache = new HashMap<String, SoftReference<Drawable>>();
}
/**
* 加载drawable
*
* @param imageUrl
* @param imageCallback
* @return drawable
*/
public Drawable loadDrawable(final String imageUrl, final ImageCallback imageCallback) {
if (imageCache.containsKey(imageUrl)) {
SoftReference<Drawable> softReference = imageCache.get(imageUrl);
Drawable drawable = softReference.get();
if (drawable != null) {
return drawable;
}
}
final Handler handler = new Handler() {
public void handleMessage(Message message) {
imageCallback.imageLoaded((Drawable) message.obj, imageUrl);
}
};
new Thread() {
@Override
public void run() {
Drawable drawable = loadImageFromUrl(imageUrl);
imageCache.put(imageUrl, new SoftReference<Drawable>(drawable));//加载后的图片添加到集合中
Message message = handler.obtainMessage(0, drawable);
handler.sendMessage(message);
}
}.start();
return null;
}
/**
* @param strUrl
* @return drawable
*/
private static Drawable loadImageFromUrl(String strUrl) {
// URL url;
// InputStream i = null;
// try {
// url = new URL(strUrl);
// i = (InputStream)url.getContent();
// } catch (Exception e) {
// e.printStackTrace();
// }
URL myFileURL;
Bitmap bitmap=null;
Drawable d = null;
try{
Get get = new Get(strUrl);//创建获取流实例
get.doGet("jainchen","jain119","jainchen@sian.cn");
InputStream is = get.getInputStream();
//解析得到图片
Options options = new Options();
options.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeStream(is,null,options);
int srcWidth = options.outWidth;
options.inJustDecodeBounds = false;
Log.i("a", "111111111111111111111111111111111");
// Log.d("Tag", "with:" + options.outWidth);
// d = Drawable.createFromStream(is, "src");
int be = 0;
be = (int) Math.round(((((double) srcWidth) / ((double) 90))));
options = new Options();
options.inSampleSize = be;
is.close();
Get get1 = new Get(strUrl);//创建获取流实例
get1.doGet("jainchen","jain119","jainchen@sian.cn");
InputStream iss = get1.getInputStream();
bitmap = BitmapFactory.decodeStream(iss, null, options);
Log.i("a", options.outWidth+"");
d = new BitmapDrawable(bitmap);
//关闭数据流
iss.close();
}catch(Exception e){
e.printStackTrace();
}
// Log.i("a", bitmap.getRowBytes()+"++++++++++++++");
// Drawable ds = ImageOrButton.resizeImage(bitmap);
return d;
}
//回调函数
public inte易做图ce ImageCallback {
/**
* @param imageDrawable
* @param imageUrl
*/
public void imageLoaded(Drawable imageDrawable, String imageUrl);
}
}
为什么上个页面跳转到这个页面的时候回卡住?每次都要卡个几秒后才能跳转。有哪位前辈可以帮忙解决下!!!万分感谢! --------------------编程问答-------------------- 怎么没人?
补充:移动开发 , Android