• 14
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Problems with Transaction of one fragment to another

I have working code , when user goes from 1 fragmeent to another, but problem is, that when New Fragment is opened, old fragment is also dispalyed under.

So user is seeing new fragment, but when he scroll down, he will also old fragment. Is there an option, to totally hide previous fragment?

if(userDTO.getMobile().isEmpty()) {
            new AlertDialog.Builder(getActivity())
                    .setView(getLayoutInflater().inflate(R.layout.test2, null))
                    .setPositiveButton(R.string.okaypopup2,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                    AppCompatActivity activity = (AppCompatActivity) view.getContext();
                                    ProfileSetting myFragment = new ProfileSetting();
                                    activity.getSupportFragmentManager().beginTransaction()
                                            .replace(R.id.zopa, myFragment)
                                            //.addToBackStack(null)
                                            .commit();
                                }
                            })
                    .show();
        }

Maybe I'm doing something wrong.. i Expect to open new fragment, when popup message appears.

Thank you

Change this statement

activity.getSupportFragmentManager().beginTransaction()
                                        .replace(R.id.zopa, myFragment)
                                        //.addToBackStack(null)
                                        .commit();

To this

activity.getSupportFragmentManager().beginTransaction()
                                        .replace(((ViewGroup)(getView().getParent())).getId(), myFragment)
                                        //.addToBackStack(null)
                                        .commit();

I think you are passing the fragment id not the Activity container id in replace

  • 1
Reply Report

Add a tag to your old Fragment, get a reference and remove it at any time that is convenient to you. Something along the lines of:

Fragment fragment = getSupportFragmentManager().findFragmentByTag(YOUR_FRAG_TAG);
if(fragment != null)
    getSupportFragmentManager().beginTransaction().remove(fragment).commit();
  • 0
Reply Report

Try this,

Fragment fragment = getSupportFragmentManager().findFragmentByTag(YOUR_FRAG_TAG);
if(fragment != null)
    getSupportFragmentManager().beginTransaction().remove(fragment).commit();
  • 0
Reply Report