【问题标题】:Android Studio GridLayout toggle all buttonAndroid Studio GridLayout 切换所有按钮
【发布时间】:2016-09-09 17:23:34
【问题描述】:

我正在使用带有 MyView.java 类的 Gridlayout。我从GridLayout得到了代码。

我在 GridLayout 下实现了另一个按钮。我想用这个按钮切换所有(GrigLayout-)按钮。有谁知道我该怎么做?

谢谢!!!

【问题讨论】:

    标签: android button toggle grid-layout


    【解决方案1】:

    您必须修改所有子视图,并检查它们是否是切换按钮。这里是一个例子,当你想切换时,调用toggleButtons(grid);

    private void toggleButtons(ViewGroup v) { 
        View a; 
        for(int i = 0; i < v.getChildCount(); i++)
         {
            a = v.getChildAt(i); 
            if(a instanceof ViewGroup) {
                toggleButtons((ViewGroup) a); 
            }
            else if(a instanceof Button){ 
                // Toggle here
            }
         }
    }
    

    【讨论】:

    • 感谢您的回答!!但是我的 gridlayout 不是 ViewGroup 或 Button 的实例,因此它永远不会到达切换案例。我必须将 Gridlayout 交给函数是否正确?
    • Android GridLayout 扩展了 ViewGroup!
    猜你喜欢
    • 2016-04-16
    • 2020-08-20
    • 2015-06-02
    • 2019-02-03
    • 2010-10-08
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    相关资源
    最近更新 更多