Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Perform Click on start of a Dialog

Ranch Hand
Posts: 79
Android Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a dialog called from Activity's onCreate. When the dialog opens, I want to perform a button click. I added btn_ok.performClick() in onStart() of the dialog. But I receive an Exception NullPointerException at Log.i statement of onClick(). If I remove that Log.i then it works and calls new LoginTask().execute.

In my onClick for that button code :

BUT the problem that I face is: If I click the button normally then the app shows the ProgressDialog (dialog = new ProgressDialog(mContext); // mContext is the context of main dialog) that is in onPre of LoginTask . But now, when I am performing the click programmatically from onStart(), I don't see the ProgressDialog. The doInBackground() work is appening (came to know from Logs) but their is no ProgressDialog to let the user know that the task has started.

It seems like this.getCurrentFocus().getId()); is throwing NullPointerException, so till onStart() is comlpeted, I don't have the focus and/or the id. Without that it can't have context to pass to the ProgressDialog and thus ProgressDialog is not showing or what ? These are just my thinkings based on logic.

How to overcome this problem ? Any help is highly appreciated.

Trupti Mehta
Ranch Hand
Posts: 79
Android Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[b]GOT IT .[/b]

Added onAttachedToWindow() method. Tested if I have getContext() in that and I do have. And I try to perform the button click and the LoginTask shows the ProgressDialog.

Thanks to all. This might help anyone who is trying somethng like me i.e. to perform a button click on start of a dialog and using its context.
Beware the other head of science - it bites! Nibble on this message:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic