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

  • SEARCH
  • Home
  • 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 7162259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:42:19+00:00 2026-05-28T13:42:19+00:00

i have made a function taketext() which returns a string value of entered text

  • 0

i have made a function taketext() which returns a string value of entered text in a text entry dialogbox. Below is the code (which is obviously incorrect). I want this to return the string only when ‘ok’ button is clicked. If the ‘if’ is removed, then it always returns null. This takeText() method is called by another method.

private String takeText() {
    String text = null;
    LayoutInflater inflater = LayoutInflater.from(this);
    View addView = inflater.inflate(R.layout.text_tag, null);
    final DialogWrapper wrapper = new DialogWrapper(addView);

    new AlertDialog.Builder(this)
            .setTitle("Enter Text")
            .setView(addView)
            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // processAdd(wrapper);
                    // text = wrapper.getData();
                    okBClicked = true;

                }
            })
            .setNegativeButton("cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int whichButton) {
                            // ignore, just dismiss
                        }
                    }).show();
    if (okBClicked)
        return wrapper.getData();
    else
    //???
}
  • 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-05-28T13:42:20+00:00Added an answer on May 28, 2026 at 1:42 pm

    Dont make your method to return string. Code it to show popup for entering string. Later, you have to get reference to your EditText defined in R.layout.text_tag and fetch its value in PositiveButton’s click event. for example:

    String text = null;
    
    private void popToTakeText() {
        LayoutInflater inflater = LayoutInflater.from(this);
        View addView = inflater.inflate(R.layout.text_tag, null);
    
        EditText txtBox = addView.findViewById(R.id.my_edit_text_box);
    
        final DialogWrapper wrapper = new DialogWrapper(addView);
    
        new AlertDialog.Builder(this)
                .setTitle("Enter Text")
                .setView(addView)
                .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // processAdd(wrapper);
                        // text = wrapper.getData();
                        okBClicked = true;
                        text = txtBox.getText();
    
                    }
                })
                .setNegativeButton("cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                                // ignore, just dismiss
                            }
                        }).show();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully made a join function, which joins an array to a string
I have made a Simple CUDA dll the code which I am displaying below.
Hi have made this function which is made to replicate an error that I
I have made some code which exports some details of a journal article to
I have made a new windows service which works fine using barebone code (just
I have made strcat() function myself but after adding the string it is printing
i have made a function which works just fine with 32-bit dates (acceptable with
I have made one function named SetControls(control controlName) which only takes control as a
I have made a function that if i check a checkbox an text will
I want to define a function available_translations which lists the translations I have made

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.