2012-07-23 5 views
1

내용보기는 LinearLayout입니다. 우리는 그것을 llOne이라고 부를 것이고 llOne.xml 파일에 있다고 말할 것입니다.(파일에서) 사용자 정의 레이아웃을 다른 레이아웃에 추가

내가 추가하려고하는 뷰는 LinearLayout이지만 별도의 파일에 있습니다. 우리는 그것을 llTwo라고 부르며 llTwo.xml 파일에 있다고 말할 것입니다.

setContentView(R.layout.llOne); 

LinearLayout llOne = (LinearLayout) findViewById(R.id.llOne); 
LinearLayout llTwo = (LinearLayout) findViewById(R.id.llTwo); 

llOne.addView(llTwo); //NullPointerException 

답변

2

당신이 내가 필요 정확히입니다 만 llOne

LayoutInflater inflater = (LayoutInflater) mContext 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View otherView = inflater.inflate(R.layout.yourSecondLayoutFileName, null); 

다음

LinearLayout llTwo = (LinearLayout) otherView .findViewById(R.id.llTwo); 
llOne.addView(llTwo); 
+0

감사를 팽창 setContentView로, 두 번째 레이아웃을 팽창 할 필요가있다. – snotyak

관련 문제