Dialog problem.

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Dialog problem.

Postby wolandino » Tue Jan 05, 2010 10:01 am

Hello,
I need help.

We have some handler:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private OnClickListener refreshOnClick = new OnClickListener() {
  3.  
  4.                 public void onClick(View v) {
  5.  
  6.                         Log.d(TAG,"refresh start");
  7.  
  8.                         showDialog(SOME_NUM);
  9.  
  10.                         somefunc();
  11.  
  12.                         Log.d(TAG,"refresh stop");
  13.  
  14.                 }
  15.  
  16.         };
  17.  
  18.  
Parsed in 0.043 seconds, using GeSHi 1.0.8.4


And we have:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. protected Dialog onCreateDialog(int id) {
  3.  
  4.                 switch (id) {
  5.  
  6.                
  7.  
  8.                 case SOME_NUM: {
  9.  
  10.                         Log.d(TAG,"WE ARE here");
  11.  
  12.                         Dialog dialog = new Dialog(this);
  13.  
  14.                         dialog.setContentView(R.layout.new_layout);
  15.  
  16.                         dialog.setTitle(R.string.some_title);
  17.  
  18.                         return dialog;
  19.  
  20.                 }
  21.  
  22.                
  23.  
  24.                 default:
  25.  
  26.                         break;
  27.  
  28.                 }
  29.  
  30.                 return null;
  31.  
  32.         }
  33.  
  34.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


When we click on button, and refreshOnClick run our Dialog will be shown after somefunc() is stopped, not before. But in LogCat we get:

01-05 08:50:20.080: DEBUG/programname(297): refresh start
01-05 08:50:20.090: DEBUG/programname(297): WE ARE here
................
01-05 08:50:24.491: DEBUG/programname((297): refresh stop

I need to after click on the button our Dialog will be shown at the first, and after this our somefunc() will work.
Where I wrong? What should I do?
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Top

Postby jwei512 » Tue Jan 05, 2010 11:14 am

So I think the showDialog is an asynchronous call, so what you probably want to do is something like this:

I presume that your dialog has some kind of submit or okay button? In which case move someFunc() into the onClickListener method of that button. Code wise it would look something like...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private OnClickListener refreshOnClick = new OnClickListener() {
  3.  
  4.      public void onClick(View v) {
  5.  
  6.            showDialog(SOME_NUM);  
  7.  
  8.       }
  9.  
  10. };
  11.  
  12.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. protected Dialog onCreateDialog(int id) {
  3.  
  4.           switch (id) {
  5.  
  6.            
  7.  
  8.           case SOME_NUM: {
  9.  
  10.                Dialog dialog = new Dialog(this);
  11.  
  12.                dialog.setContentView(R.layout.new_layout);
  13.  
  14.                dialog.setTitle(R.string.some_title);
  15.  
  16.                Button b = (Button) dialog.findViewById(R.id.your_button);
  17.  
  18.                b.setOnClickListener(new onClickListener() {
  19.  
  20.                      
  21.  
  22.                      @Override
  23.  
  24.                      public void onClick(View v) {
  25.  
  26.                            someFunc();
  27.  
  28.                      }
  29.  
  30.  
  31.  
  32.                }
  33.  
  34.                return dialog;
  35.  
  36.           }
  37.  
  38.           default:
  39.  
  40.                break;
  41.  
  42.      }
  43.  
  44.      return null;
  45.  
  46. }
  47.  
  48.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


This should guarantee the order you want. Let me know if it works for you.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby wolandino » Tue Jan 05, 2010 12:21 pm

Thank for advice, but I need another thing.
I have main Activity, that has a Button Refresh.
What I need?
I need after Button Refresh click we got a Dialog window, which will shown while proccess run.
I have:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. showDialog(BLA);
  3.  
  4. someFunc();
  5.  
  6. dismissDialog(BLA); // we can erase it
  7.  
  8.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


But after click our Dialog will be showm after someFunc() end.
Where to search the solution?
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Postby wolandino » Tue Jan 05, 2010 12:23 pm

May be I should some asynchronous process, where Progress Dialog will run?
And it will be dismiss after soneFunc stopped?
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Postby wolandino » Tue Jan 05, 2010 12:37 pm

I have found solution:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         private OnClickListener refreshOnClick = new OnClickListener() {
  3.  
  4.                 public void onClick(View v) {
  5.  
  6.                         showDialog(LOGGED);
  7.  
  8.                         Thread thread = new Thread(ActivityName.this);
  9.  
  10.                         thread.start();
  11.  
  12.                 }
  13.  
  14.         };
  15.  
  16.        
  17.  
  18.         public void run() {
  19.  
  20.                 getLastMessages();
  21.  
  22.         handler.sendEmptyMessage(0);
  23.  
  24. }
  25.  
  26.  
  27.  
  28. private Handler handler = new Handler() {
  29.  
  30.         public void handleMessage(Message msg) {
  31.  
  32.                         dismissDialog(LOGGED);
  33.  
  34.         }
  35.  
  36. };
  37.  
  38.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 13 guests