gpt4 book ai didi

android - 在android中获取RadioGroup计数

转载 作者:行者123 更新时间:2023-11-29 00:23:06 26 4
gpt4 key购买 nike

我正在线性布局中创建多个(动态)radiogroup。每个都有 4 个单选按钮。在该 linearLayout 中有一些 TextViews

我的问题是按下按钮时,我需要获取所有 radioGroup 以获取数据。

我尝试了以下方法,但得到了包括 textViews 在内的全部计数

LinearLayout ll=(LinearLayout)findViewById(R.id.questions_lay);
int childcount = ll.getChildCount();

有什么想法吗?提前致谢

最佳答案

你可以使用

public void getViewType(ViewGroup viewGroup)
{
for (int index = 0; index < viewGroup.getChildCount(); index++)
{
View childView = viewGroup.getChildAt(index);

if (childView instanceof RadioGroup)
{
System.err.println("RadioGroup " + index);
getViewType((ViewGroup) childView);
}
else if (childView instanceof RadioButton)
{
System.err.println("RadioButton " + index);
}
else if (childView instanceof TextView)
{
System.err.println("TextView " + index);
}
}
}

当您获得 instanceOf RadioGroup 时,如果您想访问其中的 RadioButton,您可以再次调用 getViewType radio 组

关于android - 在android中获取RadioGroup计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com