2017-08-26 11 views
1

listitem(フラグメント)をクリックするとオープンフラグメントが必要ですが、失敗しました。エラーlogcatはありません。断片化するためのフラグメント

fragment_item_two.xml:

<FrameLayout 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="layout.ItemTwoFragment" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <!-- TODO: Update blank fragment layout --> 
    <ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</FrameLayout> 

fragment1(リストビュー):(ItemTwoFragment.java)

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

    View view = inflater.inflate(R.layout.fragment_item_two, container, false); 
    BottomNavigationView bottomNavigationView = (BottomNavigationView) 
      view.findViewById(R.id.navigation); 

    contactList = new ArrayList<>(); 
    lv = (ListView) view.findViewById(R.id.list); 
    new GetContacts().execute(); 

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> pa, View v, int p, long id) { 
      int itm = (int) pa.getItemAtPosition(p); 

      fragmentManager = getActivity().getSupportFragmentManager(); 
      FragmentTransaction transaction = fragmentManager.beginTransaction(); 
      transaction.replace(R.id.fragmentContainer, new NewsFragment()); 
      transaction.commit(); 

     } 
    }); 

    return view; 
} 

NewsFragment:

public class NewsFragment extends Fragment { 
} 

fragment_news:

<FrameLayout 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="layout.NewsFragment"> 

    <!-- TODO: Update blank fragment layout --> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="news fragment" /> 

</FrameLayout> 

この問題を解決するにはどうすればよいですか?またはこの場合の参考資料を教えてもらえますか?おかげ

答えて

0

あなたのフラグメント

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

    View rootView = inflater.inflate(R.layout.fragment_news, container, false); 

    // Your code .... 

    return rootView; 
} 
を膨らませることを忘れ
関連する問題