Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:30:32+00:00 2026-06-17T08:30:32+00:00

In my MainActivity , I generate a DialogAlert with 2 EditText s inside. I

  • 0

In my MainActivity, I generate a DialogAlert with 2 EditTexts inside.
I want to recover my 2 EditTexts in my MainActivity when I click on the Positive Button in the DialogAlert.

Here my DialogAlert class:

public class ShareDialog extends DialogFragment{

    public interface ShareDialogListener {
        public void onDialogPositiveClick(DialogFragment dialog);
        public void onDialogNegativeClick(DialogFragment dialog);
    }

    ShareDialogListener mListener;
    private Handler mResponseHandler;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
           mListener = (ShareDialogListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement ShareDialogListener");
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();

        View v = inflater.inflate(R.layout.dialog_share, null); 
        final EditText name_place =    (EditText)v.findViewById(R.id.sharePlaceName);
        final EditText description_place = (EditText)v.findViewById(R.id.shareDescription);
        builder.setView(v)
                .setTitle(R.string.shareTitle)
               .setPositiveButton(R.string.share, new DialogInterface.OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int id) {
                       String name = name_place.getText().toString();
                       String description = description_place.getText().toString();
                       mListener.onDialogPositiveClick(ShareDialog.this);

                   }
               })
               .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       mListener.onDialogNegativeClick(ShareDialog.this);
                       ShareDialog.this.getDialog().cancel();
                   }
               });      
        return builder.create();
}

}

My MainActivity implements ShareDialog.ShareDialogListener

In my MainActivity I have:

    public void onClickShare(View v) {
         // Create an instance of the dialog fragment and show it
        DialogFragment dialog = new ShareDialog();
        dialog.show(getSupportFragmentManager(), "ShareDialog");
    }

    public void onDialogPositiveClick(DialogFragment dialog) {
        Toast.makeText(this, "Position Shared", Toast.LENGTH_SHORT).show();

    }

    public void onDialogNegativeClick(DialogFragment dialog) {
        Toast.makeText(this, "Cancel Share", Toast.LENGTH_SHORT).show();

    }

When I click the Positive Button in the DialogAlert, I have a Toast with “position shared”.

I would like to recover in the method onDialogPositiveClick() from MainActivity my params name and description created in my DialogAlert

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:30:33+00:00Added an answer on June 17, 2026 at 8:30 am

    Just modify the onDialogPositiveClick method to provide the params:

    public interface ShareDialogListener {
        public void onDialogPositiveClick(DialogFragment dialog, String name, String description);
        public void onDialogNegativeClick(DialogFragment dialog);
    }
    

    In your alert:

    mListener.onDialogPositiveClick(ShareDialog.this, name_place.getText(), description_place.getText());
    

    And in your activity:

    public void onDialogPositiveClick(DialogFragment dialog, String name, String description) {
        Toast.makeText(this, "Position Shared: " + name + ", " + description, Toast.LENGTH_SHORT).show();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here goes my mainactivity.java public class MainActivity extends Activity { Button iol; @Override protected
My title is pretty self explanatory. Here's my code: public class MainActivity extends Activity
public class MainActivity extends Activity { Button b; //FrameLayout fl; @Override protected void onCreate(Bundle
This is my static inner class for creating an AlertDialog inside my MainActivity class:
I have 2 tabs, named : Tab1, Tab2 class MainActivity extends TabActivity. MainActivity.java public
I need to make onPause() event in MainActivity class. Is it possible somehow generate
My application code is as follows, public class Alarm extends MainActivity { public String
Here, TabView is the class which adds this particular fragment. Search is the MainActivity
public class MainActivity extends Activity implements Runnable{ private int progressBarStatus = 0; private Handler
Here is my service class import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.