私はグーグル2009を見ていましたが、私のコードが非効率的であり、メモリの問題を引き起こす可能性があることに気づきました。
これは私の実装です
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder;
if(li == null){
li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if(convertView == null){
convertView = li.inflate(R.layout.book_case_view, parent, false);
viewHolder = new ViewHolder();
viewHolder.image = (ImageView)convertView.findViewById(R.id.bookCover);
viewHolder.textView = (TextView)convertView.findViewById(R.id.bookLabel);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
bi = dbh.getData(FILES.get(position));
convertView.setTag(position);
convertView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
BookCaseOnClick(position);
}
});
viewHolder.image.setImageResource(R.drawable.book);//Create a drawable backup cover
viewHolder.textView.setText( bi.getBook_Title());//Object refers to Book_information
viewHolder.textView.setBackgroundResource(R.drawable.alphabet_bar_bg_dark);
// new LoadCover(image, bi).run();
LoadCover(viewHolder.image, bi, position);
return convertView;
}
static class ViewHolder{
ImageView image;
TextView textView;
}
ただし、最初のサイクルがロードされた後、この行でエラーが発生しました。(二つ目)
viewHolder = (ViewHolder) convertView.getTag();
これらはエラーです。注意すべき主な点は、デバッグ中に例外が検出され、「java.lang.integer」エラーでgridviewクラスに渡されたことです。
08-16 20:13:02.073: E/AndroidRuntime(6520): FATAL EXCEPTION: main
08-16 20:13:02.073: E/AndroidRuntime(6520): java.lang.ClassCastException: java.lang.Integer
08-16 20:13:02.073: E/AndroidRuntime(6520): at epub.activity.View_Book_Selection_Screen$BookCaseAdapter.getView(View_Book_Selection_Screen.java:835)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.AbsListView.obtainView(AbsListView.java:1409)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.GridView.makeAndAddView(GridView.java:1222)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.GridView.makeRow(GridView.java:268)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.GridView.fillDown(GridView.java:221)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.GridView.fillFromTop(GridView.java:340)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.GridView.layoutChildren(GridView.java:1136)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.os.Looper.loop(Looper.java:123)
08-16 20:13:02.073: E/AndroidRuntime(6520): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-16 20:13:02.073: E/AndroidRuntime(6520): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 20:13:02.073: E/AndroidRuntime(6520): at java.lang.reflect.Method.invoke(Method.java:507)
08-16 20:13:02.073: E/AndroidRuntime(6520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-16 20:13:02.073: E/AndroidRuntime(6520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-16 20:13:02.073: E/AndroidRuntime(6520): at dalvik.system.NativeStart.main(Native Method)