Android App Close without Error, on click of the first gridview Item

南楼画角 提交于 2020-01-17 04:25:08

问题


i have a fragment which displays a gridview with images.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.hotelgallery, container, false);

    gridView = (GridView) v.findViewById(R.id.gridView);
    gridAdapter = new GridViewAdapter(getActivity(), R.layout.grid_item_layout, getData(getActivity()));
    gridView.setAdapter(gridAdapter);

    gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageItem item = (ImageItem) parent.getItemAtPosition(position);
            //Create intent
            Intent intent = new Intent(getActivity(), FullScreenImageActivity.class);
            intent.putExtra("title", item.getTitle());
            ByteArrayOutputStream bs = new ByteArrayOutputStream();
            item.getImage().compress(Bitmap.CompressFormat.PNG, 50, bs);
            intent.putExtra("image", bs.toByteArray());
            //Start details activity
            startActivity(intent);
        }
    });

    return v;
}

When an item is clicked, i'm displaying a FullScreen Activity with the image that the user is clicking. The above code works perfectly when i click all the images except of the first. When the first item of the gridview is clicked the app is closing, without having any errors.

Any idea about that?

来源:https://stackoverflow.com/questions/29867827/android-app-close-without-error-on-click-of-the-first-gridview-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!