android fragment call from custom dialog

377 views Asked by At

i am calling fragment from custom dialog. but i cant call fragment. my onClick calling function

  public void text_noteClick(View v){
    Fragment fragments = new Text_Note_Fragment();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.layout.note_text, fragments);
    transaction.addToBackStack(null);
    Toast.makeText(getApplicationContext(),"text",Toast.LENGTH_SHORT).show();
}

Toast is works successfully. Text_Note_Fragment class is

public class Text_Note_Fragment extends Fragment {
public Text_Note_Fragment() {

}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view;
    view = inflater.inflate(R.layout.note_text,container,false);
    return view;
}

} i think problem is Fragment replacing function. sorry for my English :) TNX

1

There are 1 answers

5
zdd On BEST ANSWER

I guess this line is the root cause.

transaction.replace(R.layout.note_text, fragments);

I see you use R.layout.note_text in onCreateView function, that's the layout xml for your fragment. but why you use it in replace function? you should use a container(often a FrameLayout), like this.

transaction.replace(R.id.container, fragments);