2014-10-13 5 views
2

나는 GridLayout과에 추가하기 위해 R.id.itemView 팽창하고 있습니다 :

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040015 type #0x12 is not valid 
그러나

View item = getLayoutInflater().inflate(R.id.itemView,null); 

, 나는 그것을 팽창이 오류를 얻고있다

해당 리소스 번호는 itemView에 해당합니다 (R.java에서 확인). 여기 (고해상도/레이아웃 color_view.xml)를 itemView가있는 파일입니다

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res/com.example.colors" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center_horizontal"> 

    <View 
     android:id="@+id/itemView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_margin="5dp" 
     android:background="@drawable/color_shape" /> 

</RelativeLayout> 

내가 구축하고 R.java 삭제, 청소 시도했지만이 문제를 해결 나던. 이 문제의 원인은 무엇입니까?

답변

1

inflate의 첫 번째 인수에는 레이아웃 인 만 사용할 수 있습니다. 에만이 같은 레이아웃 팽창 할 수

View item = getLayoutInflater().inflate(R.layout.color_view,null); 
0

할 당신이 사용에게 viewtoadd을 수행

LayoutInflater inflater = getLayoutInflater(); 
View layout= inflater.inflate(R.layout.color_view, null); 
View viewtoadd = layout.findViewById(R.id.itemView); 

이; 건배