这是我的第一个问题,我是新开发者,我试图显示列表中存在的图像,我想将它们保存在sqlite数据库中,这是我的代码(我拿了来自数据库远距离的图像,我在列表视图中以此代码显示它们,但它对我来说并不好看):
public class GetImagesFromDropBox extends Activity {
ListView list;
InputStream is;
ImageView img, img2,myconvertimage;
Button btn, btn2;
ImageView imageView;
Bitmap bitmapOrg;
String result = "";
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db=this.openOrCreateDatabase("test.db",Context.MODE_PRIVATE, null);
db.execSQL("create table tb if not exists tb (a blob )");
StrictMode.ThreadPolicy threadPolicy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(threadPolicy);
setContentView(R.layout.listeimages);
Vector<Bitmap> ImageList = get_From_Cloud();
SetTheList(ImageList);
}
private void SetTheList(Vector<Bitmap> cantactList) {
list = (ListView) findViewById(R.id.listviewimages);
ArrayAdapter<Bitmap> adapter = new MY_ArrayAdapter(GetImagesFromDropBox.this,R.layout.rowimages, cantactList);
list.setAdapter(adapter);
/* list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View viewClicked, int position,long id) {
saveImage(viewClicked);
}
private void saveImage(View view ) {
FileInputStream fis = new FileInputStream();
}});*/
}
public class MY_ArrayAdapter extends ArrayAdapter<Bitmap> {
Vector<Bitmap> liste_user;
public MY_ArrayAdapter(Context context, int resource,
Vector<Bitmap> liste_user) {
super(context, resource, liste_user);
this.liste_user = liste_user;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View ItemView = convertView;
if (ItemView == null) {
ItemView = getLayoutInflater().inflate(R.layout.rowimages,parent, false);
}
Bitmap curentUser = liste_user.get(position);
ImageView img=(ImageView)ItemView.findViewById(R.id.imagefromdropboxxx);
img.setImageBitmap(curentUser);
return ItemView;
}
}
private Vector<Bitmap> get_From_Cloud() {
String str1 = "";
Vector<Bitmap> imageviewslist = new Vector<Bitmap>();
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("mode", "charger"));
nameValuePairs.add(new BasicNameValuePair("nom", "img1200"));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://thecloudtelecom.esy.es/uplodefilee.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
int j = 0;
while ((line = reader.readLine()) != null) {
j++;
if (j >= 3) {
sb.append(line + "\n");
}
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
// Parse les données JSON
try {
Vector<ImageBytes> imagebyte = new Vector<ImageBytes>();
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
int id = json_data.getInt("id");
String nom = json_data.getString("nom");
str1 = json_data.getString("contenue");
Log.e(" ID of image ", " " + id);
imagebyte.add(new ImageBytes(nom, id, str1));
}
for (int i = 0; i < imagebyte.size(); i++) {
byte[] ba2 = Base64.decode(imagebyte.get(i).getBa());
Bitmap bitmap = BitmapFactory.decodeByteArray(ba2, 0, ba2.length);
imageviewslist.add(bitmap);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return imageviewslist;
}
}