getView方法的代码是这样的:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inf = getLayoutInflater();
View v;
v = inf.inflate(R.layout.rowdetails, parent, false);
TextView _tvname = (TextView)v.findViewById(R.id.tvname);
ImageView _ivimg = (ImageView)v.findViewById(R.id.ivimg);
Car_setget c = new Car_setget();
c = arrlist.get(position);
_tvname.setText(c.getname());
//loader.displayImage(c.getimg(), _ivimg, op, null);
ImageDownloader task = new ImageDownloader();
try {
Bitmap image = task.execute(c.getimg()).get();
_ivimg.setImageBitmap(image);
} catch(Exception e) {
e.printStackTrace();
}
return v;
}
}
//ImageDownloader.java
public class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... urls) {
// TODO Auto-generated method stub
try {
URL url = new URL(urls[0]);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
InputStream is = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(is);
return bitmap;
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
}
我怎么解决这个问题?我想在该线程中创建一个新线程,我想声明getView
方法的整个主体。有可能吗?请帮帮我。
答案 0 :(得分:0)
试试这个:
3