سؤال

I'm trying run this code :

Fragment resultFrag = getSupportFragmentManager().findFragmentByTag("dialogoimagen");
        if (resultFrag != null) {
            DialogImagen dialogonuevo = DialogImagen.newInstance(usuario,indicesql,titulo,anuncio,url,esUsuario);
            getSupportFragmentManager().beginTransaction().replace(resultFrag.getId(), dialogonuevo).addToBackStack(null).commit();
        }

this way says: Must use non-zero containerViewId ... I dont know which is the containerViewId in a DialogFragment that I must introduce in replace (http://developer.android.com/reference/android/support/v4/app/FragmentTransaction.html#replace%28int,%20android.support.v4.app.Fragment,%20java.lang.String%29)

Any help is welcome

هل كانت مفيدة؟

المحلول

The replace(resultFrag.getId(), dialogonuevo) method is expecting a view id to use as the container for the fragment - the view will be replaced with the fragment). You are passing it the fragments ID, which is currently null.

Usually you would have a FrameLayout in your layout file, with an id of something like R.id.fragment, and your replace call would look like:

replace(R.id.fragment, dialogonuevo)

Also, it seems that your dialogonuevo fragment may be some kind of DialogFragment? In this case you would want to use the show() method of the dialogfragment, instead of a fragment transaction.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top