Shures
Shures

Reputation: 25

Fragment inside fragment not working

I have made a fragment inside another fragment and When i click on the list item in list , it works because toast method shows the message but new fragment is not adding... it shows remains same....

   @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TextView T_profile_name = (TextView) view.findViewById(R.id.profile_name);
             TextView T_profile_hometown = (TextView) view.findViewById(R.id.profile_hometown);

             String user_name = T_profile_name.getText().toString();
             String  user_hometown = T_profile_hometown.getText().toString();
             String getID = user_id[position];

            SharedPreferences sharedPreferences = getActivity().getSharedPreferences("comm_data", getContext().MODE_PRIVATE);
            String getid = sharedPreferences.getString("user_id", "");
             Toast.makeText(getContext(), user_name+" "+user_hometown+" "+getID+""+getid, Toast.LENGTH_SHORT).show();


             //mSocket.emit("message", "getuser");
            FragmentManager fragmentManager = getChildFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.add(new Chat_box(),"chat_box");
            fragmentTransaction.addToBackStack("chat");
            fragmentTransaction.commit();

Upvotes: 0

Views: 100

Answers (1)

Sony
Sony

Reputation: 7186

You should tell the fragment manager to add the fragment somewhere. as @Mike said, use FragmentTransaction#add(int,Fragment, String). Your code should be fragmentTransaction.add(R.id.the_container,new Chat_box(),"chat_box");

Upvotes: 3

Related Questions