我编写了动态显示记录的代码。问题是,在我更改了设备的方向几次后,我的应用程序崩溃了。这可能是记忆问题吗?如果是,请您提供有关如何释放内存和停止内存泄漏的步骤。
LinearLayout lh1 = (LinearLayout) view.findViewById(R.id.lLibrary);
lh1.removeAllViews();
final LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < libraryListFromDB2.size(); i++) {
UserLibrary library = libraryListFromDB2.get(i);
LinearLayout lv = (LinearLayout) inflater.inflate(R.layout.imageLayout_layout, null);
TextView tvType = (TextView) lv.findViewById(R.id.tvlibraryType);
TextView tvName = (TextView) lv.findViewById(R.id.tvlibraryName);
TextView tvDate = (TextView) lv.findViewById(R.id.tvlibraryDate);
tvName.setText("text");
String expiryDate = getExpirationDate();
String expiresDisplayDate = "";
if(expiryDate != null && expiryDate.length() > 0){
DateFormat df = new SimpleDateFormat("MM/dd/yyyy",Locale.getDefault());
DateFormat outputformat = new SimpleDateFormat("MM/dd",Locale.getDefault());
Date date = null;
try {
date = df.parse(expiryDate);
calendar.setTime(date);
libraryExpiryMonth = calendar.get(Calendar.MONTH)+1;
expiresDisplayDate = outputformat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
}
ImageView imageView = (ImageView) lv.findViewById(R.id.libraryThumbNails);
imageView.setOnClickListener(clickMeListenerLibrary);
String imageURL = library.getThumbnail();
if(imageURL != null) {
String displayImagePathSmall = imageURL;
String displayImagePathSmallfileName = displayImagePathSmall.substring(displayImagePathSmall.lastIndexOf("/") + 1);
if(displayImagePathSmallfileName != null && displayImagePathSmallfileName != "") {
File imgFile = new File(getActivity().getBaseContext().getFilesDir(), displayImagePathSmallfileName);
imageView.setImageURI(Uri.fromFile(imgFile));
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
}
}
lh1.addView(lv);
}