2014-10-16 9 views
0

간단한 활동을하고있어 주 활동에 사용자가 스 와이프하여 이동할 수있는 부분이 두 개 있습니다. 그들 중 한 명은 맞춤 목록을 갖고 싶습니다. 예를 들어 https://github.com/JakeWharton/SwipeToDismissNOA과 같이 목록의 각 항목을 스 와이프하여 삭제할 수 있습니다. ListFragment 내부에서 작업 할 일반 목록을 가져올 수 있었지만이 사용자 지정 목록을 작동시키지 못했습니다. 알다시피, ListFragment에는 하나의 간단한 .xml이 있어야하지만, 사용하려는 하나의 .xml에는 좀 더 많은 것들이 있습니다. 이런 식으로 뭔가 : ListFragment 또는 Fragment의 사용자 정의 ListView?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:baselineAligned="false" 
android:padding="16dp"> 

<LinearLayout android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="8dp" 
    android:orientation="vertical"> 

    <TextView android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     style="?android:listSeparatorTextViewStyle" 
     android:text="ListView" /> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" /> 
</LinearLayout> 
내가) (위에서 getListView하려고이 .XML을 사용하여, 그것은 null을 반환하거나 또는 내가 이런 일을 수행하려고 할 때입니다 그래서 : 보기보기 = 인플레이터를. inflate (R.layout.fragment_section_dummy, null); ListView ls = (ListView) view.findViewById (android.R.id.list); 10 ~ 15 20 : 25 : 28.895이 : E/AndroidRuntime (8081) : java.lang.UnsupportedOperationException가 : addView (보기의 LayoutParams)이 어댑터 뷰 AdapterView에서 지원되지 않습니다

그것은이 오류가 발생합니다.

감사합니다.

답변

0

내 자신의 ID로 가장 쉬운 작업이므로 ListView ID를 다른 ID로 변경합니다. 예를 들어 android:id="@+id/myList"을 선택합니다.

조각에서 onCreateView 방법으로 레이아웃을 팽창시키고 ID로 뷰를 가져옵니다.

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.yourDummyLayout, container, false); 


     //You should get your ListView there 
     ListView yourListView = rootView.findViewById(R.id.myList); 

     [......] 

     return rootView; 
    } 

시도해보십시오. 행운을 빌어 요!

관련 문제