# Fill a Gridview with Adapter in Fragment

**URL:** <https://discuss.kotlinlang.org/t/fill-a-gridview-with-adapter-in-fragment/18752>\
**Category:** Android\
**Created:** [August 12, 2020, 12:26pm UTC](https://discuss.kotlinlang.org/t/fill-a-gridview-with-adapter-in-fragment/18752 "2020-08-12T12:26:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![HydraRock](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HydraRock](https://discuss.kotlinlang.org/u/HydraRock)\
**Post date:** [August 12, 2020, 12:26pm UTC](https://discuss.kotlinlang.org/t/fill-a-gridview-with-adapter-in-fragment/18752/1 "2020-08-12T12:26:31Z")

</div>

Hi everyone,  
i am trying to fill a Gridview with an adapter.  
The Gridview is contained in a Fragment  
Normally it is something that I do well but in the same view, I am trying to adapt the code even following some articles on the net but the gridview does not fill up and I don’t even have an error.  
I put a brackpoint in the Adapter (PiecesAdater) function, but I didn’t enter it unlike other views where I use it and enter, so I guess there is something wrong with calling it.  
I was thinking that it was the context that is not good but even trying to change it never enters.  
This is the code I am using

```
 try{

        //var myNumberAdapter = PiecesAdater(getActivity()!!.getApplicationContext(), listPieces)

        var myAdapter = PiecesAdater(container!!.getContext(), listPieces)
        val view: View = layoutInflater.inflate(R.layout.fragment_pieces_fiche_client, null)
        gv_ListPieces = view.findViewById<View>(R.id.piecesClient) as GridView
        gv_ListPieces!!.setAdapter(myAdapter)
    }
    catch (ex: Exception){
        println(ex.message)
    }

inner class PiecesAdater : BaseAdapter {

    var listOfPosts = ArrayList<Piece>()
    var context: Context? = null

    constructor(context: Context, listOfPosts: ArrayList<Piece>) : super() {
        this.context = context
        this.listOfPosts = listOfPosts
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {

        val post = listOfPosts[position]
        var inflator =context!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var myView = inflator.inflate(R.layout.pieces, null)

        myView.txtPieceTitle.text = post.title
        myView.txtPieceData.text = post.date
        return myView

    }

```

}

Do you have any suggestions?  
Thank you
