1

I am currently stuck by adding a GridView to a row of a ListView, which uses different Layouts for each row. In my humble opinion this should be possible, shouldn't it?. Or how should this be done? Although I always receive a NullPointerException and don't know why.

I use the following code to generate the views for my ListView. The second view should add the GridView to the ListView:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int type = getItemViewType(position);
        if (convertView == null) {
            switch (type) {
                case TYPE_ITEM0:
                    convertView = mInflater.inflate(R.layout.foto_details_headline, null);
    /* Logic for first Row of the ListView */
                    break;
                case TYPE_ITEM1:

                    convertView = mInflater.inflate(R.layout.foto_details_gridview, null);
                    GridView gridview = (GridView) findViewById(R.id.gridview);
                    Context m = getApplicationContext();
                    int s = mData.get(0).pictures.size();

    //le wild null pointer appears                        
                    gridview.setAdapter(new FotoDetailsImageAdapter(convertView.getContext(), mData.get(0).pictures));
                    break;

            }

        }

        return convertView;
    }

The NullPointer appears when I want to set the Adapter (FotoDetailsImageAdapter). Context and pictures are not null - I have already proved this. I suspect that something is wrong with the context which is handled over to the ImageAdapter.

All in all it should look similar to my iOS application - where I have implemented the same logic (also with a listview). The second row consists of a GridView.

enter image description here

Any Ideas? Is it possible to nest a GridView inside a ListView? And how should this be done?

Bins Ich
  • 1,822
  • 6
  • 33
  • 47

1 Answers1

0

you can put GridView inside ScrollView. Here is Youtube link http://www.youtube.com/watch?v=kNX996ZZ2CI

In this case GridView will be scrollable

ihrupin
  • 6,932
  • 2
  • 31
  • 47