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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:21:44+00:00 2026-06-10T15:21:44+00:00

i have a small problem with writing my application.. I have custom dialog what

  • 0

i have a “small” problem with writing my application..
I have custom dialog what is show after click on button.
On this custom dialog i have some textviews and buttons..
i want the following: if i click on button in the dialog, application will start call (its not the point of problem, it would does whatever).

But problem is, that i am not able to write the listener. All the time if i write the listener in xml layout file, i get crash of my application.
There is one solution – write the listener like a anonymous listener. But i dont like anonym listeners so much (if you have 100buttons in layout and for all buttons you need to add anonym listener the code will be pretty confused).

i am not sure if i need to write View.OnClickListener() or DialogInterface.OnClickListener() – i think that the first one but i am not sure. Anonym listener works with view one, non anonym (over the xml layout file) doesnt work the one and the seconds as well.. can anyone say me “why”??

codes:

this work:

    b.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Log.e("err","I am here");   
        }
    });

this doesnt work:

-xml_layout_file

<Button 
    android:id="@+id/btn_startCall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClick_startCall"
    android:text="@string/btn_startCall" /> 

-myDialog.java (extends Dialog)

public void onClick_startCall(View v){
    Log.e("err","I am here");       
}

output from log:

08-31 22:08:05.469: W/dalvikvm(9456): threadid=1: thread exiting with uncaught exception (group=0x40a3b1f8)
08-31 22:08:05.475: E/AndroidRuntime(9456): FATAL EXCEPTION: main
08-31 22:08:05.475: E/AndroidRuntime(9456): java.lang.IllegalStateException: Could not find a method onClick_startCall(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'btn_startCall'
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.view.View$1.onClick(View.java:3031)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.view.View.performClick(View.java:3511)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.view.View$PerformClick.run(View.java:14105)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.os.Handler.handleCallback(Handler.java:605)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.os.Looper.loop(Looper.java:137)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.app.ActivityThread.main(ActivityThread.java:4673)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at java.lang.reflect.Method.invokeNative(Native Method)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at java.lang.reflect.Method.invoke(Method.java:511)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at dalvik.system.NativeStart.main(Native Method)
08-31 22:08:05.475: E/AndroidRuntime(9456): Caused by: java.lang.NoSuchMethodException: onClick_startCall [class android.view.View]
08-31 22:08:05.475: E/AndroidRuntime(9456):     at java.lang.Class.getConstructorOrMethod(Class.java:460)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at java.lang.Class.getMethod(Class.java:915)
08-31 22:08:05.475: E/AndroidRuntime(9456):     at android.view.View$1.onClick(View.java:3024)
08-31 22:08:05.475: E/AndroidRuntime(9456):     ... 11 more
  • 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-10T15:21:46+00:00Added an answer on June 10, 2026 at 3:21 pm

    The Dialog class does not extend Context, which is required for the onClick attribute.

    From the documentation

    This name must correspond to a public method that takes exactly one parameter of type View. For instance, if you specify android:onClick=”sayHello”, you must declare a public void sayHello(View v) method of your context (typically, your Activity).


    You can do this:

    OnClickListener startButtonListener = new View.OnClickListener() {
        public void onClick(View v) {
            Log.e("err","I am here");   
        }
    });
    

    And reference it later on:

    b.setOnClickListener(startButtonListener);
    

    If this helps you organize your code better (I like it, along with Orabig’s suggestion).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currenty writing small application for image processing. However I have a big problem
I have a problem with Regular Expressions. I'm writing a small program that matches
I am writing a small console application in C# that references a custom assembly
I am writing a small application in Classic ASP. I have a page which
I writing small application in pure C++. But now I encourage strange problem. I
Writing a small application in order to demonstrate certain functionality. I have an embedded
I have been writing a small web application in C# .NET4.0 to try and
I'm writing a dynamic application and one problem I have is that I have
I have a small question about a problem I encountered writing my first python
I am currently writing a small rolodex application for my own benefit and have

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.