Android: GridView cell as downstate button


#1

Hi,

I want to make a cell react in the same way a button would.
So on press down I want the cell to change colour and on release return to its original colour.
Is that possible?

Ive tried… SingleSelection mode but that doesnt give the desired effect as it stays selected on mouse up


#2

Hello Aidan

The gesture detection model implemented on the ShinobiGridView unfortunately (as I think you have discovered) only responds to the onSingleTapUp gesture. 

It may be possible to implement your desired functionality with a little work, using some of the Android RecyclerView’s own API. Whilst I have not tried this myself, you may be able to achieve what you want with steps similar to the following:

Obtain a reference to the desired GridRecyclerView (data and header if necessary) using this api:

https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiGridsAndroid/1.0.0/Standard/Normal/apidocs/reference/com/shinobicontrols/grids/core/ShinobiGridView.html#getDataRecyclerView()

https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiGridsAndroid/1.0.0/Standard/Normal/apidocs/reference/com/shinobicontrols/grids/core/ShinobiGridView.html#getHeaderRecyclerView()

You should be able to safely cast a GridRecyclerView to a RecyclerView.

You should be able to set your own custom OnItemTouchListener to the RecyclerView, as was done in this post:

This means you can potentially write code to select the cell on singleTapDown, and de-select in on singleTapUp.

You should be able to learn the adapter position of the child View which was tapped, using the RecyclerView method (as done in the post) getChildAdapterPosition. 

Once you know the adapter position of the item which was tapped, you can select it or de-select it using this api:

https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiGridsAndroid/1.0.0/Standard/Normal/apidocs/reference/com/shinobicontrols/grids/core/GridRecyclerView.html#setItemSelected(int,%20boolean)

I hope that this helps,

Thanks,

Kai.