2014-11-03 2 views
0

У меня проблема с фрагментом. Внутри диалога есть диалог внутри фрагмента и фрагмент. Но когда я добавляю второй фрагмент, есть IllegalArgumentException : No view found for id ***** (fr.*****:id/container_list_collections) for fragment FragmentCollectionVignette.IllegalArgumentException Фрагмент в диалоге

FragmentHP.java

public class FragmentHP extends Fragment { 

/** Bouton Ajouter à **/ 
private Button btAddTo; 

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

    getFragmentManager().beginTransaction().replace(R.id.container_dernier_ajout, new FragmentDerniersAjoutsHP()).commit(); 
    getFragmentManager().beginTransaction().replace(R.id.container_collections, new FragmentCollectionsHP()).commit(); 
    getFragmentManager().beginTransaction().replace(R.id.container_ebooks, new FragmentEbooksHP()).commit(); 
    getFragmentManager().beginTransaction().replace(R.id.container_games, new FragmentGamesHP()).commit(); 
    getFragmentManager().beginTransaction().replace(R.id.container_software, new FragmentSoftwareHP()).commit(); 
    getFragmentManager().beginTransaction().replace(R.id.container_digital_creation, new FragmentDigitalCreationHP()).commit(); 

    btAddTo = (Button) vueFragmentHP.findViewById(R.id.bt_collections); 

    btAddTo.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      LayoutInflater inflater = getActivity().getLayoutInflater(); 
      View view = inflater.inflate(R.layout.dialog_add_to, null); 
      final Dialog dialog = new Dialog(getActivity()); 

      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(view); 
      dialog.show(); 
      dialog.setCanceledOnTouchOutside(false); 

      Button btValider = (Button) view.findViewById(R.id.bt_add_to); 

      getFragmentManager().beginTransaction().add(R.id.container_list_collections, new FragmentCollectionVignette()).commit(); 
     } 
    }); 

    return vueFragmentHP; 
} 

}

dialog_add_to.xml

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <TextView 
     android:id="@+id/tv_add_to" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/add_to"/> 
    <TextView 
     android:id="@+id/tv_choose_collection" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/choose_collection" 
     android:layout_below="@id/tv_add_to"/> 

    <FrameLayout 
     android:id="@+id/container_list_collections" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/tv_choose_collection"/> 
    <Button 
     android:id="@+id/bt_add_to" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/valider" 
     android:layout_below="@id/container_list_collections"/> 
</RelativeLayout> 

В чем проблема? (Извините за мой английский очень плохо)

+0

Вы пробовали очистить свой проект? Иногда смена ресурсов не восстанавливает R-файл. – Marius

+0

Да, но у меня такая же ошибка – MichelRobico

ответ

0

я думаю, что проблема в этой строке getFragmentManager() BeginTransaction() добавить (R.id.container_list_collections, новый FragmentCollectionVignette()) совершить()...; ....

изменить это на this.getActivity() getFragmentManager() BeginTransaction() добавить (R.id.container_list_collections, новый FragmentCollectionVignette()) совершить();

+0

Существует такая же ошибка ... – MichelRobico

+0

Вы хотите отобразить другой фрагмент при нажатии кнопки диалога. –

+0

Я хочу вставить фрагмент в диалоговом окне. – MichelRobico

Смежные вопросы