2012-03-18 7 views
1

1日中、フラグメント内で動作するリストビューを取得しようとしました。私は理由を知っていませんが、何らかの理由で私がそれをやろうとしているような形で、それは決して景色を膨らませたくありません。私はそれが違いを作る場合、私はそうは思わないと思うactionbarsherlockを使用しています。相続人は私のレイアウトが失敗したクラス:Android - ListFragmentがsetContentViewで失敗する

public class GraffSearch extends FragmentActivity implements ActionBar.TabListener{ 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.searchlayout);//<-------------fails here 

    final ActionBar ab = getSupportActionBar(); 

    for (int i = 1; i < 4; i++) { 
     ab.addTab(ab.newTab().setText("Tab " + i).setTabListener(this)); 
    } 


    ab.show(); 
    if (ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_TABS) { 
     ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
    } 



} 

@Override 
public void onTabReselected(Tab tab, FragmentTransaction ft) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onTabSelected(Tab tab, FragmentTransaction ft) { 
    //Toast.makeText(this, "tabs work "+tab.getPosition()+" user id is "+avrid, Toast.LENGTH_LONG).show(); 
    SearchListFrag fragment = (SearchListFrag) getSupportFragmentManager().findFragmentById(R.id.searchfrag); 
    //fragment.updateUrl(tab.getPosition(), avrid); 

} 

@Override 
public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
    // TODO Auto-generated method stub 

} 

}

とHERESにレイアウトは、私は私のフラグメントを呼び出しました。

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


<ListFragment 
    android:id="@+id/searchfrag" 
    android:layout_width="0dip" 
    android:layout_height="match_parent" 
    android:name="graffit.main.SearchListFrag" 
    android:layout_weight="1"></ListFragment> 



</LinearLayout> 

EDIT:私のsearchlistfragクラス

public class SearchListFrag extends Fragment{ 

ListView markList; 

public SearchListFrag(){}; 

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
    markList = (ListView) inflater 
       .inflate(R.id.searchlist, container, false);//<----------Fails Here 
    markList.setAdapter(new OrderAdapter(
      MixView.mixContext.getBaseContext(), 
      R.layout.searchinnerlistlayout, 
      MixView.dataView.dataHandler.markerList)); 


    // return inflater.inflate(R.layout.searchlistlayout, container, false); 
    return markList;    

    } 


    @Override 
    public void onPause() { 

     super.onPause(); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 

    } 

    public void updateUrl(int tab, String avrid) { 

    } 

    private class OrderAdapter extends ArrayAdapter<Marker> { 

     private ArrayList<Marker> marks; 

     public OrderAdapter(Context context, int textViewResourceId, ArrayList<Marker> items) { 
       super(context, textViewResourceId, items); 
       this.marks = items; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
       View v = convertView; 
       if (v == null) { 
        LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        v = vi.inflate(R.layout.searchinnerlistlayout, null); 
       } 
       // Order o = items.get(position); 
       if (marks.get(position) != null) { 
         TextView title = (TextView) v.findViewById(R.id.title); 
         //TextView description = (TextView) v.findViewById(R.id.description); 
         if (title != null) { 
           title.setText("Title: "+marks.get(position).getTitle());       } 
         //if(description != null){ 
         // description.setText("Description: "+ +marks.get(position).get); 
         // } 
         ImageView icon = (ImageView) v.findViewById(R.id.markimage); 
         icon.setImageBitmap(marks.get(position).getBitmap()); 
       } 

       return v; 
     } 
} 
} 

EDIT:私のsearchlistlayoutレイアウト

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
<ListView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:name="@+id/searchlist"></ListView> //<----this is the id i use that fails 

</LinearLayout> 

アイブ氏は、定期的なフラグメントとしてlistfragmentを使用してから行ったり来たり、いくつかの異なる設定を試してみました同じ結果。 logcatをheresします。

EDIT:新しいログ猫

03-18 15:34:45.939: E/AndroidRuntime(20704): FATAL EXCEPTION: main 
03-18 15:34:45.939: E/AndroidRuntime(20704): java.lang.RuntimeException: Unable to start activity ComponentInfo{graffit.main/graffit.main.GraffSearch}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.ActivityThread.access$1500(ActivityThread.java:124) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.os.Looper.loop(Looper.java:130) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.ActivityThread.main(ActivityThread.java:3806) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at java.lang.reflect.Method.invokeNative(Native Method) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at java.lang.reflect.Method.invoke(Method.java:507) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at dalvik.system.NativeStart.main(Native Method) 
03-18 15:34:45.939: E/AndroidRuntime(20704): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.support.v4.app.FragmentActivity.setContentView(FragmentActivity.java:421) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at graffit.main.GraffSearch.onCreate(GraffSearch.java:16) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660) 
03-18 15:34:45.939: E/AndroidRuntime(20704): ... 11 more 
03-18 15:34:45.939: E/AndroidRuntime(20704): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f050068 type #0x12 is not valid 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1912) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.content.res.Resources.getLayout(Resources.java:746) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.inflate(LayoutInflater.java:318) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at graffit.main.SearchListFrag.onCreateView(SearchListFrag.java:28) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:845) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1156) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:660) 
03-18 15:34:45.939: E/AndroidRuntime(20704): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 
03-18 15:34:45.939: E/AndroidRuntime(20704): ... 19 more 

答えて

4

あなたのレイアウトのフラグメントのインポートが間違っています。フラグメントは、<fragment>タグを持つレイアウトに追加されます。 Views以外では、完全修飾クラス名の後にタグを指定しないでください。このエラーは、Androidが存在しない 'ListFragment'タイプのViewを追加しようとするために発生します。

試してみてください。<fragment>は小文字でなければならない

<fragment 
    android:id="@+id/searchfrag" 
    android:layout_width="0dip" 
    android:layout_height="match_parent" 
    android:name="graffit.main.SearchListFrag" 
    android:layout_weight="1"></fragment> 

<Fragment>があまりにも動作しません。

いくつかのものを混在させます。

1)フラグメントのonCreateメソッドは、フラグメントのレイアウト全体を拡張する必要があります。 Fragmentのレイアウトを膨らませたら、ListViewを取得できます。

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View contentView = inflater.inflate(R.id.searchlist, container, false);  
    markList = (ListView) contentView.findViewById(R.id.searchlist); 
    markList.setAdapter(new OrderAdapter(MixView.mixContext.getBaseContext(), R.layout.searchinnerlistlayout, MixView.dataView.dataHandler.markerList)); 

    return contentView; 
} 

2)ListViewのIDを定義しておらず、その名前を定義しました。レイアウトを変更してください:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
<ListView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/searchlist"></ListView> 
</LinearLayout> 
+0

おかげさまで、ありがとうございました。私はリストビューを膨らませようとすると、それを使用して、今、私のフラグメントクラスで失敗しました。 –

+0

あなたのフラグメントのコード、レイアウト、エラーログを追加してください。 – thaussma

+0

もう一度教えてください –

関連する問題