0

画像のグリッド ビューを表示しようとしています。次のコードを試しましたが、実行後にアプリケーションが強制的に閉じられます。どこが間違っていますか? 私のコード:

AndroidGridLayoutActivity:

public class AndroidGridLayoutActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        GridView gv=(GridView)findViewById(R.id.grid_view);
        gv.setAdapter(new ImageAdapter(this));
    }
}

ImageAdapter.java:

public class ImageAdapter extends BaseAdapter {
                private Context mcontext;
                public Integer[] mThumbids={R.drawable.img9,R.drawable.img10,R.drawable.img11,R.drawable.img12,R.drawable.img13,R.drawable.img14};
                public ImageAdapter(Context c)
                {
                                mcontext=c;
                }

                @Override
                public int getCount() {
                                // TODO Auto-generated method stub
                                return mThumbids.length;
                }

                @Override
                public Object getItem(int position) {
                                // TODO Auto-generated method stub
                                return mThumbids[position];
                }

                @Override
                public long getItemId(int position) {
                                // TODO Auto-generated method stub
                                return 0;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                                // TODO Auto-generated method stub
                                ImageView imageView=new ImageView(mcontext);
                                imageView.setImageResource(mThumbids[position]);
                                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                                imageView.setLayoutParams(new GridView.LayoutParams(70,70));
                                return imageView;
                }



}

main.xml:

<GridView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/grid_view"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:numColumns="auto_fit"
  android:columnWidth="90dp"
  android:horizontalSpacing="10dp"
  android:verticalSpacing="10dp"
  android:stretchMode="columnWidth"/>
4

1 に答える 1