I have a activity
that calls a fragment
which is displayed as a DialogAlert
. However, when this fragment
is closed, I need a method of Activity
to be called. What is the best way to do this?
The Activity code:
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 to be called is within the onItemLongClick
method.