gpt4 book ai didi

java - 在膨胀的 LinearLayout 中通过 ID 获取元素

转载 作者:行者123 更新时间:2023-12-02 02:15:49 25 4
gpt4 key购买 nike

如何在充气的LinearLayout中通过ID获取元素?

这是我的代码,运行良好,我看到创建的子 LinearLayouts。

LinearLayout root = (LinearLayout)findViewById(R.id.linearLayoutContainer);
LayoutInflater inflater;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

final int size = grandTotalStatsRespond.getStatZoneItems().size();
for (int j = 0; j < size; j++)
{
StatZoneItem statZoneItem = grandTotalStatsRespond.getStatZoneItems().get(j);
LinearLayout l = (LinearLayout) inflater.inflate(R.layout.loader_total_stat_item, null);

// Here I need to find TableRow and TextView within LinearLayout by its ID
// and set values of statZoneItem object.

root.addView(l);
}

最佳答案

试试这个

for (int j = 0; j < size; j++)
{
StatZoneItem statZoneItem = grandTotalStatsRespond.getStatZoneItems().get(j);
LinearLayout l = (LinearLayout) inflater.inflate(R.layout.loader_total_stat_item, null);

// Here I need to find TableRow and TextView with LinearLayout by its ID

TableRow tableRow = l.findViewById(R.id.tableRowID);
TextView textView = l.findViewById(R.id.textViewID);
textView.setText("NILESH");
// and set values from statZoneItem object.

root.addView(l);
}

关于java - 在膨胀的 LinearLayout 中通过 ID 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49313446/

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