aspose file tools*
The moose likes Android and the fly likes Perform Click on start of a Dialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Perform Click on start of a Dialog " Watch "Perform Click on start of a Dialog " New topic
Author

Perform Click on start of a Dialog

Trupti Mehta
Ranch Hand

Joined: Oct 08, 2000
Posts: 79

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.


Regards,
Trupti (SCJP)
Trupti Mehta
Ranch Hand

Joined: Oct 08, 2000
Posts: 79


[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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Perform Click on start of a Dialog