我想使用网格布局(不是 GridView ),在每个单元格中我想要 ImageView ,在它下面是 TextView 。我想在网格布局的每个单元格上实现点击监听器。请有人告诉我该怎么做?
最佳答案
假设,您的单元格布局最顶层的包装器是 RelativeLayout,这是可能有效的代码:
GridLayout grid = (GridLayout) findViewById(R.id.your_layout_id);
int childCount = grid.getChildCount();
for (int i= 0; i < childCount; i++){
RelativeLayout container = (RelativeLayout) grid.getChildAt(i);
container.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
// your click code here
}
});
}
关于android - 如何在带有 ImageView 和 TextView 的网格布局上实现点击监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32116418/