2016-05-21 13 views
0

フラグメント付きナビゲーション・ドロワーがあります。私はNavigation Drawer上でFragmentを開く必要があります。コードにはエラーはありませんが、フラグメント内のリストビュー項目は表示されません。空白ページのみを表示します。次のコード。 Plzzは私を助けます。リストビュー項目がフラグメント内に表示されない

fragment_blank_fragment_trip2.xml

<LinearLayout 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" 
android:orientation="vertical" 
tools:context="com.example.administrator.vtsapplication.BlankFragmentTrip2"> 

<ListView 
android:id="@+id/mobile_list" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 
</ListView> 

</LinearLayout> 

Activity_listview.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/label" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="10dip" 
android:textSize="16dip" 
android:textStyle="bold" > 

BlankFragmenttrip2.java

package com.example.administrator.vtsapplication; 


import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class BlankFragmentTrip2 extends Fragment { 
public BlankFragmentTrip2() { 
    // Required empty public constructor 
} 
ViewGroup vg; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    String[] mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"}; 
    vg = (ViewGroup) inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false); 
    ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray); 

    ListView listView = (ListView) vg.findViewById(R.id.mobile_list); 
    listView.setAdapter(adapter); 
    return inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false); 
} 

} 
+0

私は空のビューを返していると思いますが、最後の行を削除します。単に 'vg'を返し、' onCreateView() 'のメソッドとして' ViewGroup'を送信しないでください。戻り値の型は 'View'だけです –

+0

ありがとうございました。 –

答えて

0

これはあなたのFragmentを使うべきです。 Viewは返されません。

public class BlankFragmentTrip2 extends Fragment { 

    String[] mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"}; 

    public BlankFragmentTrip2() { 
     // Required empty public constructor 
    } 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

     View rootView = inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false); 
     ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray); 

     ListView listView = (ListView) rootView.findViewById(R.id.mobile_list); 
     listView.setAdapter(adapter); 
     return rootView; 
    } 

} 
+0

ありがとうございます。その仕事と私の問題はあなたのコードを使って解決されました..ありがとう。 –

関連する問題