I want to change the color of the grid cell using the number of grid position . e.g. I have 5X6 grid means 30 gridItems so i want to change the color of 21st position. Please tell me how can i do this Without clicking on the Grid View.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
In order to set color in grid cell while inflating grid cell's layout, in your baseadapter class create a cell's array then set the color as you wish.
Like
then
here griditm is the id of the layout grid_item
First you must decide the order of the grid, where are columns, and where are lines. For example:
1 2 3 4 5
6 7 8 9 10
etc..
then just do a multiplication
I'm assuming 0 based index, that simply means: if there are 6 columns:
if there are 5 rows
0 based index allows you to iterate the whole grid in a very simple manner
You will need to define a custom adapter for this.
In the
getView()
method of adapter you'll have to check theposition
parameter if is equal with 21. If it's equal with 21, then change the background for currently cell.If you did not had the experience to define a custom adapter yet, then it will make more sense to pass through an example first.
Here's an example of a GridView that uses a custom adapter to display images.