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