@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
int type = getItemViewType(position);
switch (type) {
case TYPE_ITEM:
convertView = mLayoutInflater.inflate(R.layout.row_view,
null);
holder.imageview =
(ImageView)convertView.findViewById(R.id.imageView3);
Thread t= new Thread(new Runnable() {
@Override
public void run() {
String name=mListItems.get(position).toString();
String namer[] = name.split("\\@");
String imagenamer=namer[0];
// String imagenamer= mListItems.get(position).toString();
Uri uri1=Uri.parse("storage/sdcard/LifeMatePrivate
/ProfileImage/ProfileImage,imagechange_1,"+imagenamer+".jpg");
Uri uri2=Uri.parse("storage/sdcard/LifeMatePrivate
/ProfileImage/Default.jpg");
File file = new File("storage/sdcard/LifeMatePrivate
/ProfileImage/ProfileImage,imagechange_1,"+imagenamer+".jpg");
if (file.exists()){
System.out.println("exists");
holder.imageview.setImageURI(uri1);
}else{
holder.imageview.setImageURI(uri2);
System.out.println("storage/sdcard/LifeMatePrivate
/ProfileImage/ProfileImage,imagechange_1,"+imagenamer+".jpg"+"didnt exist");
}}
});
t.start();
break;
case TYPE_SECTION:
convertView =
mLayoutInflater.inflate(R.layout.section_row_view, null);
break;
}
holder.textView = (TextView)
convertView.findViewById(R.id.row_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(mListItems.get(position).toString());
return convertView;
}
但现在当我运行应用程序时,我的内存异常直接出现,意味着它变得更糟!这对男人来说是什么意思?我怎样才能解决我的记忆问题呢?
使用毕加索:(我的方法好吗?)
Context mContext;
public PinnedHeaderAdapter(Context context, ArrayList<String>
listItems,ArrayList<Integer> listSectionPos) {
this.mContext = context;
this.mListItems = listItems;
this.mListSectionPos = listSectionPos;
mLayoutInflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mListItems.size();
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
return !mListSectionPos.contains(position);
}
@Override
public int getViewTypeCount() {
return TYPE_MAX_COUNT;
}
@Override
public int getItemViewType(int position) {
return mListSectionPos.contains(position) ? TYPE_SECTION : TYPE_ITEM;
}
@Override
public Object getItem(int position) {
return mListItems.get(position);
}
@Override
public long getItemId(int position) {
return mListItems.get(position).hashCode();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
int type = getItemViewType(position);
switch (type) {
case TYPE_ITEM:
convertView = mLayoutInflater.inflate(R.layout.row_view,
null);
holder.imageview =
(ImageView)convertView.findViewById(R.id.imageView3);
String name=mListItems.get(position).toString();
String namer[] = name.split("\\@");
String imagenamer=namer[0];
// String imagenamer= mListItems.get(position).toString();
File file = new File("storage/sdcard/LifeMatePrivate
/ProfileImage/ProfileImage,imagechange_1,"+imagenamer+".jpg");
if (file.exists()){
Uri uri1=Uri.parse("storage/sdcard/LifeMatePrivate
/ProfileImage/ProfileImage,imagechange_1,"+imagenamer+".jpg");
System.out.println("exists");
// holder.imageview.setImageURI(uri1);
Picasso.with(mContext)
.load(uri1)
.resize(50, 50)
.centerCrop()
.into(holder.imageview);
}else{
Uri uri2=Uri.parse("storage/sdcard/LifeMatePrivate
/ProfileImage/Default.jpg");
// holder.imageview.setImageURI(uri2);
System.out.println("storage/sdcard/LifeMatePrivate
/ProfileImage/ProfileImage,imagechange_1,"+imagenamer+".jpg"+"didnt exist");
Picasso.with(mContext)
.load(uri2)
.resize(70, 70)
.centerCrop()
.into(holder.imageview);
}
break;
case TYPE_SECTION:
convertView =
mLayoutInflater.inflate(R.layout.section_row_view, null);
break;
}
holder.textView = (TextView)
convertView.findViewById(R.id.row_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(mListItems.get(position).toString());
return convertView;
}
答案 0 :(得分:0)
square.github.io/picasso使用此lib在适配器中显示图像。这个lib将解决您的问题。