2014-10-22 4 views
5

Sto provando a passare le variabili dalla mia attività principale a un frammento. Questo è il modo sto cercando di farlo:Xamarin La variabile passante di Android da attività a frammenti restituisce null

Questo è a mio attività:

Questo è a mio Frammento:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState) 
     { 

      var ignored = base.OnCreateView(inflater, container, savedInstanceState); 

      var view = inflater.Inflate(Resource.Layout.MuseumInformation, null); 

      content = this.Activity.Intent.GetStringExtra ("content"); 
      header = this.Activity.Intent.GetStringExtra ("header"); 
      footer = this.Activity.Intent.GetStringExtra ("footer"); 
      imageFilePath = this.Activity.Intent.GetStringExtra ("imageLocation"); 

Ma nessuna delle variabili vengono passati (sono tutti vuoti nel frammento). Sto chiaramente facendo un errore fondamentale qui. Qualcuno può dirmi com'è, per favore. Oppure mostrami un modo migliore per trasmettere i dati.

Grazie.

+0

'this.Activity.Intent.GetStringExtra '=>' Arguments.GetString'? – Selvin

risposta

2

Ecco come ho fatto:

content = Arguments.GetString("content"); 
header = Arguments.GetString ("header"); 
footer = Arguments.GetString("footer"); 
imageFilePath = Arguments.GetString ("imageLocation"); 
2

Nel Activity

Bundle mybundle = new Bundle(); 
mybundle.PutString("MyDataTag", "Hello"); 

FragmentTransaction fragmentTransaction = FragmentManager.BeginTransaction(); 
var myFragment = new VerifyReportFragment(); 
myFragment .Arguments = mybundle; 

nel frammento OnCreateView

String stringData= Arguments.GetString("MyDataTag"); 
Problemi correlati