Php android从mysql数据库获取图像列表
我可以使用异步任务从mysql数据库加载一个图像,但现在我想加载5个图像并在列表视图中显示它们,因此我想首先了解如何使doInbackground方法返回从mysql数据库获取的图像列表:Php android从mysql数据库获取图像列表,php,android,Php,Android,我可以使用异步任务从mysql数据库加载一个图像,但现在我想加载5个图像并在列表视图中显示它们,因此我想首先了解如何使doInbackground方法返回从mysql数据库获取的图像列表: @Override protected Bitmap doInBackground(String... params) { String id = params[0]; String add = "http://192.168.1.11/sav
@Override
protected Bitmap doInBackground(String... params) {
String id = params[0];
String add = "http://192.168.1.11/save/load_image_from_db.php?id=" + id;
URL url;
Bitmap image = null;
try {
final BitmapFactory.Options options = new BitmapFactory.Options();
//options.inJustDecodeBounds = true;
//options.inSampleSize = 4;
//options.inJustDecodeBounds = false;
url = new URL(add);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
image = BitmapFactory.decodeStream(connection.getInputStream(),null,options);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
公共类MyAsyncTask扩展了AsyncTask{
@凌驾
受保护的ArrayList doInBackground(字符串…参数){
ArrayList bmps=新的ArrayList();
对于(int i=0;i
然后用一个ID数组调用execute方法。。。瞧 在这种情况下,您必须返回图像的数组列表,代码如下所示,,(注意:我没有测试此代码)
@覆盖受保护的位图doInBackground(字符串…参数){
字符串id=params[0];
字符串add1=”http://192.168.1.11/save/load_image_from_db.php?id=“+id;
字符串add2=”http://another 照片”;
字符串add3=”http://another 照片”;
字符串[]adds={add1,add2,add3};
网址;
ArrayList imageList=新建ArrayList();
位图图像=空;
对于(int i=0;我们不能从一个URL获取图像列表吗?每个图像都有它的URL,,你说从一个URL获取图像列表是什么意思?图像列表有URL列表,这是正确的。是的,当然你可以获取一些图像并将其加载到ListView中。我想知道是否有可能编写一个php脚本来显示存储在其中的所有图像mysql数据库,并在android应用程序中使用此url从一个url获取所有图像您可以使用php从数据库获取数据,然后将其编码为JSON,,,然后从手机获取JSON并从网站下载图像和文本..截取是最好的方法。。
public class MyAsyncTask extends AsyncTask<String, Void, ArrayList<Bitmap>> {
@Override
protected ArrayList<Bitmap> doInBackground(String... params) {
ArrayList<Bitmap> bmps = new ArrayList<>();
for(int i = 0; i < params.length; i++) {
String id = params[i];
String add = "http://192.168.1.11/save/load_image_from_db.php?id=" + id;
URL url;
Bitmap image = null;
try {
final BitmapFactory.Options options = new BitmapFactory.Options();
//options.inJustDecodeBounds = true;
//options.inSampleSize = 4;
//options.inJustDecodeBounds = false;
url = new URL(add);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
image = BitmapFactory.decodeStream(connection.getInputStream(), null, options);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
bmps.add(image);
}
return bmps;
}
}
@Override protected Bitmap doInBackground(String... params) {
String id = params[0];
String add1 = "http://192.168.1.11/save/load_image_from_db.php?id=" + id;
String add2="http://another photo";
String add3="http://another photo";
String[] adds={add1, add2, add3};
URL url;
ArrayList <Bitmap> imageList=new ArrayList();
Bitmap image = null;
for (int i=0;i<adds.length;i++){
try {
final BitmapFactory.Options options = new BitmapFactory.Options(); null //options.inJustDecodeBounds = true; //options.inSampleSize = 4; null//options.inJustDecodeBounds = false;
url = new URL(adds[i]); null HttpURLConnection connection =(HttpURLConnection) url.openConnection(); nullimage = BitmapFactory.decodeStream(connection.getInputStream(),null,options); null} catch (MalformedURLException e) { e.printStackTrace(); null} catch (IOException e) { e.printStackTrace(); null}
imageList.add( image);
image=null;
}
return imageList;
}