如何在膨胀的线性布局中通过ID获取元素?
这是我的代码,它工作正常,我看到了创建的子线性布局。
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);
}