Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:在嵌套布局中访问视图需要时间吗?_Java_Android - Fatal编程技术网

Java Android:在嵌套布局中访问视图需要时间吗?

Java Android:在嵌套布局中访问视图需要时间吗?,java,android,Java,Android,我已经在rood布局中多次使用相同的布局。现在我访问嵌套布局中的视图,如下所示。时间长吗。有没有更好的解决办法 TextView tv=(TextView)findViewById(R.id.fragment_forcast).findViewById(R.id.horizontalScrollView). findViewById(R.id.liner_layout).findViewById(R.id.forcas_layout_1).findViewByI

我已经在rood布局中多次使用相同的布局。现在我访问嵌套布局中的视图,如下所示。时间长吗。有没有更好的解决办法

 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");
    }
}
private void populateForcastView(){
文本视图电视;
视图rootView=(视图)findViewById(R.id.fragment\u forcast)。findViewById(R.id.horizontalScrollView)。
findViewById(R.id.liner\U布局);

对于(int-forcastFragmentIndex=1;forcastFragmentIndexYes),请使用Butterknife库


是的,使用Butterknife库


只需通过其ID查找视图,无需嵌套ID

 TextView tv=findViewById(R.id.day_field)

只需通过ID查找视图,无需嵌套ID

 TextView tv=findViewById(R.id.day_field)

我现在明白了,我的方法错了

    private void populateForcastView(){
    TextView tv;
    for(int forcastFragmentIndex=1; forcastFragmentIndex<=3; forcastFragmentIndex++){
        int forecastFragmentId=getResources().getIdentifier("forcast_layout_" + forcastFragmentIndex, "id", getPackageName());
        tv=(TextView)findViewById(forecastFragmentId).findViewById(R.id.day_field);
        tv.setText("Sunday");
    }
}
private void populateForcastView(){
文本视图电视;

对于(int-forcastFragmentIndex=1;forcastFragmentIndex我现在知道了。我的方法是错误的

    private void populateForcastView(){
    TextView tv;
    for(int forcastFragmentIndex=1; forcastFragmentIndex<=3; forcastFragmentIndex++){
        int forecastFragmentId=getResources().getIdentifier("forcast_layout_" + forcastFragmentIndex, "id", getPackageName());
        tv=(TextView)findViewById(forecastFragmentId).findViewById(R.id.day_field);
        tv.setText("Sunday");
    }
}
private void populateForcastView(){
文本视图电视;

for(int forcastFragmentIndex=1;forcastFragmentIndex)我现在就知道了。我在答案中给出了正确的方法。我现在就知道了。我在答案中给出了正确的方法。所以现在您可以尝试使用butterknife库进行视图绑定,所以现在您可以尝试使用butterknife库进行视图绑定