neh*_*ha 1 android android-intent android-layout
我想使用网格布局(不是网格视图),并且在每个单元格中都需要图像视图,并在其下方使用文本视图。我想在网格布局的每个单元上实现点击侦听器。请有人告诉我该怎么做?
假设您的单元格布局最顶层的包装器是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
        }
    });
}
| 归档时间: | 
 | 
| 查看次数: | 9702 次 | 
| 最近记录: |