0

I'm making an android application with a navigation drawer.

I want this application to connect to the internet, and I need to put a label that contains informations about the connection into a fragment and some buttons to send information in another. I would like the label to update constantly, also if its fragment isn't shown.

My question is:

Is it possible to programmatically edit the elements of a fragment when it isn't shown?
  • why you don't pass the data in intent ?, check out this: http://stackoverflow.com/questions/12739909/send-data-from-activity-to-fragment-in-android – Kosh Dec 22 '14 at 11:32
  • but will this method actually edit my label when I open my fragment? – Lorenzo Notaro Dec 22 '14 at 11:36

1 Answers1

0

as an answer to your comment, yes and this is how it works

Bundle bundle = new Bundle();
bundle.putString("key", "actualValue");
MyFragment fragment = new MyFragment();
fragment.setArguments(bundle);
// start your fragment

and then in your fragment onCreate or onCreateView

Bundle bundle = getArguments();
if(bundle !=null){
   String actualData = bundle.getString("key");
   TextView myTextView = (TextView)view.findViewById(R.id.myText);
   myTextView.setText(actualData);
}
Kosh
  • 6,140
  • 3
  • 36
  • 67