Nella mia applicazione ho un'attività principale e diversi frammenti. quando l'utente fa clic sul pulsante Indietro, i frammenti vengono visualizzati uno alla volta. Voglio identificare quale frammento si trova attualmente nello stack posteriore. Quindi utilizzare per identificare i frammenti in base al nome del tag del frammento. Ho usato il seguente segmento di codice per ottenere il nome del tag del frammento ma restituisce sempre un valore nullo.findFragmentByTag() restituisce sempre null - Android
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
String fragmentTag = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName();
please help.
Modifica,
sostituzione frammento con tag,
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.activity_main_content_fragment, fragment, text);
hanno impostato TAG nel frammento? –
vedi la mia domanda modificata – user3800832
btw dov'è la riga 'findFragmentByTag()' ?? –