2013-06-06 2 views
2

내 주요 활동에서 내 기본 ScrollView 내에있는 LinearLayout에 액세스하려고합니다.Android : findViewById가 null을 반환하고 있습니까?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:id="@+id/graph" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="250dip" 
     /> 



</ScrollView> 

을 내 주요 활동에서 내가있는 ScrollView 팽창 한 후 다음과 같이 선형 레이아웃에 액세스하려고 : 왜 내 findViewById를가 null 여기에 반환 될

LayoutInflater inflater; 
    inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    

    ScrollView mainLayout = (ScrollView) inflater.inflate(R.layout.scrollview, 
        null); 
    LinearLayout layout = (LinearLayout) findViewById(R.id.graph); 

다음과 같이 내있는 ScrollView가 구현된다? 나는 처음에는 팽창이 끝나기 전에 그것을 찾으려고했지만, 팽창이 끝나기를 기다리는 while 루프를 시도해 봤는데, 이것은 도움이되지 않습니다.

답변

4

당신은 팽창 된 레이아웃을 그것에게 당신은 inflater.inflate에서 잘못된 레이아웃을 지정하는 경우 첫번째) (한 번 확인 할 수

LinearLayout layout = (LinearLayout) mainLayout.findViewById(R.id.graph); 
+0

대단히 감사합니다! – TrolliOlli

관련 문제