This week's book giveaway is in the Design forum.
We're giving away four copies of Experimentation for Engineers: From A/B testing to Bayesian optimization and have David Sweet on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Perform Click on start of a Dialog

 
Ranch Hand
Posts: 79
Android Java ME Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Maybe he went home and went to bed. And took this tiny ad with him:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic