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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:00:10+00:00 2026-06-07T02:00:10+00:00

Basically I’m trying to add an OnClickListener to a Button in a Dialog, however

  • 0

Basically I’m trying to add an OnClickListener to a Button in a Dialog, however by simply adding the listener, the app becomes unstable and crashes, and when I try and catch it, the message returned is null. Thanks for taking a look at my problem.

Also, if it helps, this is being triggered when a menu button is pressed.

Creating the dialog:

try {
        final Dialog dialog = new Dialog(List.this);
        dialog.setContentView(R.layout.adddialog);
        dialog.setTitle("Add to the list");
        dialog.setCancelable(true);

        final EditText et = (EditText) findViewById(R.id.itemAddDialog);
        Button ok = (Button) findViewById(R.id.okAddDialog);
        Button cancel = (Button) findViewById(R.id.cancelAddDialog);

        ok.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                //Contents of this function don't matter, It freezes simply by being created
            }
        });

        dialog.show();
        }
catch (Exception e) {
    Toast.makeText(List.this, e.getMessage(), Toast.LENGTH_LONG).show();
}

(Slightly trimmed) XML file:

<LinearLayout
    android:id="@+id/btnpaneAddDialog"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" >

    <Button
        android:id="@+id/okAddDialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add it" />

    <Button
        android:id="@+id/cancelAddDialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cancel" />


</LinearLayout>

  • 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-07T02:00:12+00:00Added an answer on June 7, 2026 at 2:00 am

    Change:

    Button ok = (Button) findViewById(R.id.okAddDialog);
    

    to

    Button ok = (Button) dialog.findViewById(R.id.okAddDialog);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to check the extended permissions the user has granted my app.
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically, what I'm trying to create is a page of div tags, each has
Basically I'm attempting to add rows to a table, I need to do this
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically, I'm implemeting a reversi app for android for my year 13 coursework and
Basically, I'm developing a note-taking app where the user can type as long as
Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.
Basically i'm trying to build a comment system. The user looks at a photo
Basically, what I am trying to do is to find last section of PE

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.