0
I have a activity
who calls a fragment
which is displayed in the form of a DialogAlert
. But when that fragment
is closed, need a method of Activity
be called. What is the best way to do this?
The code of Activity:
package activities;
import classes.Event;
import adapters.EventListAdapter;
import android.app.FragmentManager;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemLongClickListener;
import br.bytecode.tarefas.R;
import database.Database;
import fragments.ViewEventFragment;
public class EventsActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_events);
loadEvents();
getListView().setOnItemLongClickListener(
(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent,
View view, int position, long id) {
Event event = (Event) parent
.getItemAtPosition(position);
FragmentManager fm = getFragmentManager();
ViewEventFragment viewEvent = ViewEventFragment
.newInstance(event);
viewEvent.show(fm, "frag_view_event");
return true;
}
}));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
getMenuInflater().inflate(R.menu.menu_events, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.menu_events_new:
Intent newEvent = new Intent(this, ManagementActivity.class);
startActivity(newEvent);
return true;
case R.id.menu_events_logoff:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
}
@Override
public void onResume() {
super.onResume();
loadEvents();
}
public void loadEvents() {
Database db = new Database(this);
EventListAdapter adapter = new EventListAdapter(this, db.readEvents());
setListAdapter(adapter);
}
}
The Fragment I want to trigger the function when called is within the method onItemLongClick
.
Viewnewevent is a
DialogFragment
? You want to run something when the Dialog is closed by cancellation or once it is closed (no matter how)?– Wakim
Yes, it is a Dialogfragment. I want it to be executed when it is closed, no matter how.
– Renan Lazarotto