2016-06-04 1 views
0

나는 같은 레이아웃을 여러 번 rood layout.Now에서 다음과 같이 중첩 된 레이아웃으로보기에 액세스하고 있습니다. 오랜 시간이 걸릴 것입니다. 더 나은 해결책이 있습니까?Android : 중첩 된 레이아웃의보기에 액세스하는 데 시간이 필요합니까?

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"); 
    } 
} 
+0

지금 받으십시오. 대답에 올바른 접근 방식을 게시했습니다. –

답변

1

그냥 findView, 필요

TextView tv=findViewById(R.id.day_field) 
+0

나는 루드 레이아웃에서 동일한 레이아웃을 여러 번 사용했습니다. –

+0

이제 뷰 바인딩에 버터 나이프 라이브러리를 사용할 수 있습니다. –

0

나는 지금 그것을 얻을. 내 접근 방식이 잘못되었습니다.

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"); 
    } 
} 
관련 문제