2014-10-02 4 views
0

내 코드에 내 조각에 새 목록보기를 만들려고하는데 문제가 있습니다. 맞춤 서랍을 사용하는 메신저.조각 사용자 정의 서랍에 listview를 만듭니다

이 코드와 53 번째 줄에 내 오류가 있습니다.View rootView = inflater.inflate (R.layout.fragment_layout_schedule, container, false); // 오류 코드 여기에

이 내 전체 코드입니다.

package com.example.blackcustomzier.skripsi; 

import android.app.ListFragment; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.SimpleAdapter; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 

/** 
* Created by Blackcustomzier on 10/2/14. 
*/ 
public class FragmentSchedule extends ListFragment { 


    // Array of strings storing country names 
    String[] countries = new String[] { 
      "India", 
      "Pakistan", 
      "Sri Lanka", 
      "China", 
      "Bangladesh", 
      "Nepal", 
      "Afghanistan", 
      "North Korea", 
      "South Korea", 
      "Japan" 
    }; 

    // Array of strings to store currencies 
    String[] currency = new String[]{ 
      "Indian Rupee", 
      "Pakistani Rupee", 
      "Sri Lankan Rupee", 
      "Renminbi", 
      "Bangladeshi Taka", 
      "Nepalese Rupee", 
      "Afghani", 
      "North Korean Won", 
      "South Korean Won", 
      "Japanese Yen" 
    }; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     Log.d("ZZZ", "ada di oncreateView"); 
     super.onCreate(savedInstanceState); 
     View rootView = inflater.inflate(R.layout.fragment_layout_schedule, container, false); 
     List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); 

     for(int i=0;i<10;i++){ 
      HashMap<String, String> hm = new HashMap<String,String>(); 
      hm.put("txt", "Country : " + countries[i]); 
      hm.put("cur","Currency : " + currency[i]); 
      aList.add(hm); 
     } 

     // Keys used in Hashmap 
     String[] from = { "flag","txt","cur" }; 

     // Ids of views in listview_layout 
     int[] to = {R.id.txt,R.id.cur}; 

     // Instantiating an adapter to store each items 
     // R.layout.listview_layout defines the layout of each item 
     SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.listview_layout, from, to); 

     setListAdapter(adapter); 

     return rootView; 
    } 

} 

이 내 fragment_layout_schedule

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <fragment 
     android:id="@+id/country_fragment" 
     android:name="com.example.blackcustomzier.skripsi.FragmentSchedule" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</RelativeLayout> 

하고 이것을 catlog 오류

10-02 07:59:42.207 2103-2103/com.example.blackcustomzier.skripsi E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
      at com.example.blackcustomzier.skripsi.FragmentSchedule.onCreateView(FragmentSchedule.java:53) 
      at android.app.Fragment.performCreateView(Fragment.java:1695) 
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:861) 
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035) 
      at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137) 
      at android.app.Activity.onCreateView(Activity.java:4746) 

덕분에 당신이 포함되지 않은 레이아웃을 확장하려고하기 때문입니다

+0

스택 추적과 fragment_layout_schedule.xml을 게시 할 수 있습니까? – ucsunil

+0

@sunil 내 fragment_layout_schedule.xml을 첨부했습니다. –

+0

무엇이 오류입니까? –

답변

0

전 ID가 "@android : id/list"인 ListView 개체 레이아웃 객체에이 객체가 있어야합니다. 당신이하려고하는 것은 정규 조각을 팽창시키고 목록 조각을 이것에 매핑하는 것입니다. 그러나 ListFragment를 매핑 할 Backing ListView 객체가 없다는 것이 있습니다.

목록 조각에 대한 사용자 지정보기를 만드는 방법은 http://developer.android.com/reference/android/app/ListFragment.html의 설명을 참조하십시오.

관련 문제