我在 Rood 布局中多次使用相同的布局。现在我正在访问嵌套布局中的 View ,如下所示。时间长吗。有没有更好的解决办法。
TextView tv=(TextView)findViewById(R.id.fragment_forcast).findViewById(R.id.horizontalScrollView).
findViewById(R.id.liner_layout).findViewById(R.id.forcas_layout_1).findViewById(R.id.day_field)
更新:这是我的方法:
private void populateForcastView(){
TextView tv;
View rootView=(View)findViewById(R.id.fragment_forcast).findViewById(R.id.horizontalScrollView).
findViewById(R.id.liner_layout);
for(int forcastFragmentIndex=1; forcastFragmentIndex<=3; forcastFragmentIndex++){
int forcastFragmentId=getResources().getIdentifier("forcast_layout_" + forcastFragmentIndex, "id", getPackageName());
tv=(TextView)rootView.findViewById(forcastFragmentId).findViewById(R.id.day_field);
tv.setText("Sunday");
}
}
最佳答案
是的,使用 Butterknife 库。
关于java - 安卓 : Does accessing view in nested layout takes time?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37631986/