[英]images are not displayed properly
我正在制作一個使用lazylist顯示圖像和文本的Android應用程序。
我從服務器的json
獲取數據。 當我手動將一些數據和圖像路徑輸入到mysql數據庫中時,這些圖像會在應用程序中正確顯示。
但是當我從移動攝像頭拍攝圖像並上傳該圖像時,它會在mysql數據庫中正確插入路徑,但它不會顯示在我的應用程序中。
有人能告訴我為什么會遇到這個問題嗎? 我的logcat中沒有出錯。
有其他人有這個問題嗎? 如果是,那么你是如何解決的? 請幫我。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_list);
inboxList = new ArrayList<HashMap<String, String>>();
List<String> profile_photo = new ArrayList<String>();
List<String> userName = new ArrayList<String>();
List<String> place = new ArrayList<String>();
list=(ListView)findViewById(R.id.list);
//adapter=new LazyAdapter(this, tS, mTitles);
list.setAdapter(adapter);
/********************************/
JSONObject json = userFunctions.homeData();
Log.e("Data", json.toString());
// Check your log cat for JSON reponse
// Log.d("Inbox JSON: ", json.toString());
try {
data = json.getJSONArray("data");
Log.d("inbox array: ", data.toString());
// looping through All messages
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
// Storing each json item in variable
String uid = c.getString("uid");
String name = c.getString("name");
String success = c.getString("success");
String profile_img = c.getString("profile_photo");
//String date = c.getString(TAG_DATE);
JSONObject places = c.getJSONObject(TAG_PLACES);
String place_photo = places.getString(TAG_PLACE_IMG);
Log.e("place_photo", place_photo);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put("uid", uid);
map.put("name", name);
map.put("success", success);
map.put("profile_image", profile_img);
profile_photo.add(profile_img);
userName.add(name);
place.add(place_photo);
// adding HashList to ArrayList
inboxList.add(map);
}
profile_image = new String[profile_photo.size()];
user_name = new String[userName.size()];
place_image = new String[(place.size())];
profile_photo.toArray(profile_image);
userName.toArray(user_name);
place.toArray(place_image);
adapter = new LazyAdapter(this, profile_image, user_name, place_image);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
/*******************************/
}
這是懶惰的適配器類
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private String[] name;
private String[] place_photo;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, String[] d, String[] username, String[] place_image) {
activity = a;
data = d;
name = username;
place_photo = place_image;
//Log.e("path", d.toString());
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.home_list_item, null);
//TextView text=(TextView)vi.findViewById(R.id.text);
TextView title = (TextView)vi.findViewById(R.id.username);
ImageView image=(ImageView)vi.findViewById(R.id.image);
ImageView place=(ImageView)vi.findViewById(R.id.place);
//text.setText("item "+position);
title.setText(name[position]);
imageLoader.DisplayImage(data[position], image);
imageLoader.DisplayImage(place_photo[position], place);
return vi;
}
}
但是當我從移動攝像頭拍攝圖像並上傳該圖像時,它確實在mysql數據庫中正確插入了所有路徑,但它仍未在我的應用程序中顯示
新圖像和舊圖像的URL是否相同?
如果是這樣,則可能是圖像緩存的情況。 ImageLoader使用URL作為密鑰緩存圖像....清除App數據后再試一次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.