小弟是Android開發新手,最近遇到了一個問題,就是在GridView裡放照片時,
上下滑動會變得很lag
這是我的ArrayAdapter的getView()
public class PhotoAdapter extends ArrayAdapter<PhotoList>{
private int resourse;
private List<PhotoList> PhotoLists;
FrameLayout item;
ImageView select;
public PhotoAdapter(Context context,int resourse,List<PhotoList> p){
super(context,resourse,p);
this.resourse=resourse;
this.PhotoLists=p;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
//讀取目前位置物件
final PhotoList pList= getItem(position);
if(convertView==null){
item=new FrameLayout(getContext());
LayoutInflater li=(LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(resourse,item, true);
}else {
item = (FrameLayout) convertView;
}
TextView textView=(TextView)item.findViewById(R.id.title);
TextView dateView=(TextView)item.findViewById(R.id.date_text);
select=(ImageView)item.findViewById(R.id.select_item);
ImageView photoView=(ImageView)
item.findViewById(R.id.content);
Bitmap bitmap=BitmapFactory.decodeFile(pList.getPhotoPath());
contextView.setImageBitmap(bitmap);
textView.setText(pList.getTitle());
dateView.setText(pList.getLocaleDate());
select.setVisibility(pList.isSelect()? View.VISIBLE : View.INVISIBLE);
return photoView;
}
每次在跑的時候,
都會出現The application may be doing too much work on its main thread.
請問應該要怎麼解決呢..?
q