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 8539293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:19:48+00:00 2026-06-11T11:19:48+00:00

Instead of using EditTexts, I have elected to use clickable categories that prompt a

  • 0

Instead of using EditTexts, I have elected to use clickable categories that prompt a Dialog that accepts a user’s input. This reusable Dialog class is stored in an AllMethods.class. The initial theory was that I pass a bunch of text (for description, title, and such) and a target TextView (to setText that the user inputted in the Dialog). However, upon execution, I get the nullpointer exception when trying to do the TextView.setText(str) line of code.

So, My question: How do I successfully change the textView OR pass a string back only after the user clicks the OK button?

Also note, that the TextView had been declared and instantiated. I assume the nullpointer is because it is in a remote class. Here is the code:

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

public class AllMethods {


    //fieldRequest is a reusable prompt to get a user's input for a field without taking up so much space
    /* Legend of inputs:
     * requestingActivity=the activity which is prompting the popup
     * dialogMessage = the description of the editText being requested
     * dialogTitle = the title to be displayed on the dialogbox
     * editTextHint = the Hint attribute that will give the user an example of the expected input
     * inputType = numeric, text, phone number, etc
     */



    public static void fieldRequest(Activity activity, String dialogMessage, String dialogTitle, final TextView outputText, int inputType, String optionalFieldSuffix){
        final Dialog dialog= new Dialog(activity);
        dialog.setContentView(R.layout.dialog_layout);
        dialog.setTitle(dialogTitle);
        //If the message/description exists, put it in
        if(dialogMessage!=null||dialogMessage!=""){TextView description = (TextView) dialog.findViewById(R.id.dialog_description);
        description.setText(dialogMessage);
        }
        //Identify the editText, set the input type appropriately and fill in the hint if applicable
        final EditText inputField = (EditText) dialog.findViewById(R.id.dialog_inputbox);
        if(Integer.toString(inputType)!=null){inputField.setInputType(inputType);}

        if(optionalFieldSuffix!=null){TextView suffix = (TextView) dialog.findViewById(R.id.dialog_optionalFieldSuffix);            
        suffix.setText(optionalFieldSuffix);}

        ImageButton dialogCancel = (ImageButton) dialog.findViewById(R.id.dialog_cancel);
        ImageButton dialogDone = (ImageButton) dialog.findViewById(R.id.dialog_done);
        dialogCancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                dialog.dismiss();

            }
        });

        dialogDone.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                outputText.setText(inputField.getText().toString());
                dialog.dismiss();

            }
        });

        dialog.show();
    }

}
  • 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-11T11:19:50+00:00Added an answer on June 11, 2026 at 11:19 am

    Implement the interface in your class like this, as shown below. You do not need to pass the textview as input to this function.

    import android.app.Activity;
    import android.app.Dialog;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.TextView;
    
    public class AllMethods {
    
    
        //fieldRequest is a reusable prompt to get a user's input for a field without taking up so much space
        /* Legend of inputs:
         * requestingActivity=the activity which is prompting the popup
         * dialogMessage = the description of the editText being requested
         * dialogTitle = the title to be displayed on the dialogbox
         * editTextHint = the Hint attribute that will give the user an example of the expected input
         * inputType = numeric, text, phone number, etc
         */
    
    
    
        public static void fieldRequest(Activity activity, String dialogMessage, String dialogTitle, int inputType, String optionalFieldSuffix, final DialogResponse dr){
            final Dialog dialog= new Dialog(activity);
            final DialogResponse dialogResponse = dr;
            dialog.setContentView(R.layout.dialog_layout);
            dialog.setTitle(dialogTitle);
            //If the message/description exists, put it in
            if(dialogMessage!=null||dialogMessage!=""){TextView description = (TextView) dialog.findViewById(R.id.dialog_description);
            description.setText(dialogMessage);
            }
            //Identify the editText, set the input type appropriately and fill in the hint if applicable
            final EditText inputField = (EditText) dialog.findViewById(R.id.dialog_inputbox);
            if(Integer.toString(inputType)!=null){inputField.setInputType(inputType);}
    
            if(optionalFieldSuffix!=null){TextView suffix = (TextView) dialog.findViewById(R.id.dialog_optionalFieldSuffix);            
            suffix.setText(optionalFieldSuffix);}
    
            ImageButton dialogCancel = (ImageButton) dialog.findViewById(R.id.dialog_cancel);
            ImageButton dialogDone = (ImageButton) dialog.findViewById(R.id.dialog_done);
            dialogCancel.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    dialogResponse.actionNo();
                    dialog.dismiss();
    
                }
            });
    
            dialogDone.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    dialogResponse.actionYes(inputField.getText().toString());
                    dialog.dismiss();
                }
            });
    
            dialog.show();
        }
    
        public interface DialogResponse {
            public void actionYes(String str);
    
            public void actionNo();
        }
    
    
    }
    

    Usage:

    DialogUtility.DialogResponse dr = new DialogResponse() {
    
                @Override
                public void actionYes(String str) {
                    // TODO Auto-generated method stub
    
                     **// your code to set your string to textview**
                }
    
    
    
                @Override
                public void actionNo() {
    
                }
            };
            **//Make sure you modify code to match your variables**
             AllMethods
                    .fieldRequest(activity, dialogMessage, dialogTitle, inputType, optionalFieldSuffix, dr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instead of using an interface like this: public interface IStartable { void Start(); void
This is pretty much a duplicate question but instead of using Castle Dynamic Proxy
I've developed a dialog box that prompts a user to enter his/her phone number
I am trying to understand the use of XAML instead using it as markup
Suppose I have a class that represents a product to be priced using one
I have a question about the dialog() function of Jquery. I wonder if instead
So I have a helper that I'm using to swap my header image for
I have class that extends 'IntentService' - this class occasionally receives data from a
I have a collapsible menu item that is defined in XML like this: <item
I have a scenario, for example, a EditText in acitivity instead of using Textview

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.