0

I have a Tab Interface with two separate activities, lets call them ActA and ActB. Both of these activities can launch a custom Dialog, and I would like to have a button within this dialog call a method of ActBs, (ActB is a ListView of a database, and the method in question is to fill the list, basically refresh). How could I have the dialog box activity reference ActB to call its method? Thanks!

EDIT: I'll give some more details. I worked this program off of Google's Notepad tutorial which teaches about SQLite DBs. I took that and split it into two activities, one for creating the entries, and then saving them (ActA); and another for viewing the entries (ActB). Now, more recently, I put those activities in tabs rather than accessing them through the phone's menu key. Unfortunately, this appears to have stopped the ListActivity from calling its "fillData()" method.

Nick
  • 6,900
  • 5
  • 45
  • 66

3 Answers3

1

If you are extending android Dialog class you can implement a Dismiss Listener in your Activity's and set it when you create the Dialog, and then in the listener implement any functionality you want depending on the button that was used to dismiss the Dialog.


If your custom Dialog is an Activity itself and you call it with a startActivity you can change it for a startActivityForResult, and implement in the refresh button of the Dialog a setResult with a custom Intent to inform the calling Activity to refresh itself.

For more info on how to use startActivityForResult look here.

Community
  • 1
  • 1
Lucas S.
  • 13,391
  • 8
  • 46
  • 46
  • Uh, actually, nothing. It haven't overridden it, so I'm doing whatever super.show() does. – Nick Dec 22 '10 at 04:49
  • I have added an alternative solution to use when you are extending Android Dialog class instead of implementing your Dialog as another Activity. – Lucas S. Dec 22 '10 at 04:56
  • Well, would you recommend implementing my dialog as an activity? How do I use the Dismiss Listener with a ListActivity class? I feel completely thick, sorry for all the questions, haha – Nick Dec 22 '10 at 05:17
  • Okay, actually, awesome, I got my OnDismissListener working from the dialog called from ActB, where the actual list is. Now I just need to make it do the same thing if the dialog from ActA is dismissed. – Nick Dec 22 '10 at 13:09
0
ImageButton button= (ImageButton) dialog.findViewById(R.id.imageButton5);      
button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        finish();
        Intent myIntent = new Intent(getBaseContext(), Abc.class);
        startActivity(myIntent);
    }
});

Try this code to start new activity from Dialog Button click.

Tisho
  • 8,320
  • 6
  • 44
  • 52
Irshad Khan
  • 794
  • 6
  • 21
0

A) One way is to use Broadcasts and BroadcastReceiver: http://developer.android.com/reference/android/content/BroadcastReceiver.html You define certain intent filters for your activities, then send the broadcast via sendBroadcast(intent), where the intent triggers the method in your activities.

B) Another way: define an interface that both activities are implementing, i.e. handleDialogButton. Since you pass the context in the dialogs constructor, you can execute some action on them.

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192