Note that there are some explanatory texts on larger screens.

plurals
  1. POFragment UI not updated when calling method from Activity
    text
    copied!<p>I have an activity class CreateEventPage, this basically calls a fragment in the onCreate method which loads the form for creating a event. On pressing a particular button, the showMapFragment() method is called which replaces this fragment with MyMapFragment object (extending the Fragment class) .</p> <p>CreateEventPage class is as follows :</p> <pre><code>public class CreateEventPage extends FragmentActivity implements MapLongPressListener { private CreateEventFragment eventFragment; private MyMapFragment mapFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragmentcontainer); eventFragment = new CreateEventFragment(); getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, eventFragment).commit(); // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first fragment } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.create_event_page, menu); return true; } public void showTimePickerDialog(View v) { DialogFragment newFragment = new TimePickerFragment(); newFragment.show(getSupportFragmentManager(), "timePicker"); } public void showDatePickerDialog(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } public void showMapFragment(View v) { // If the frag is not available, we're in the one-pane layout and must swap frags... // Create fragment and give it an argument for the selected article mapFragment = new MyMapFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, mapFragment); transaction.addToBackStack(null); transaction.commit(); } @Override public void MapLongPressed(String locationAddress, double latitude, double longitude) { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.replace(R.id.fragment_container, eventFragment).commit(); eventFragment.initPositions(locationAddress, latitude, longitude); } } </code></pre> <p>when i call the initPositions method of the eventFragment object , I try and update a EditText object's text field. However, the UI does not get updated. I have tried running the method on UI thread as well, it still doesn't update. view is a global variable which stores the View object returned by onCreateView method of the fragment. The initPositions method is as follows:</p> <pre><code>public void initPositions( String address, double lat, double longi) { EditText location = (EditText) view.findViewById(R.id.LocationText); latitude = lat; longitude = longi; location.setText(address); Log.i("Init Positions", address); Log.i("Init Positions", ""+latitude); Log.i("Init Positions", ""+longitude); Log.i("Init Positions", inputLocation.getText().toString()); } </code></pre> <p>However, in spite of all this, the UI does not get updated even though the log prints the correct values as I desire. Can you please tell me what I am doing wrong?</p> <p>Thanks, Rohit</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload