Android Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingAndroid Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 1st, 2012, 07:04 AM
svijiya svijiya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 21 svijiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 49 m 29 sec
Reputation Power: 0
How to make AlertDialog wait for user input?

I have searched for my problem in google and I did not find any answers yet.

My problem is I want to show an alert dialog from my activity prompting the user to save, cancel, or exit when the user click on 'new' button. I used AsyncTask to start the dialog process. The problem is the dialog does not wait for the user input. The rest of the code after a thread is started executes and the whole programming logic goes havoc.

partial code relating to this problem is given below.

// do the coding for click on add button
bac.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
new CallAlert().execute("");
}
}

..... rest of the code

CallAlert code
public class CallAlert extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String...inputs)
{
String result;
result = getInput("Data Changed", "Do you want to Save Before Exit", ccontext);
if (result == null)
{
result = "";
}
return result;
}


@Override
protected void onPostExecute(String result)
{
if (result.equalsIgnoreCase("YES"))
{
Toast.makeText(ccontext, "Clicked On Yes", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(ccontext, "Clicked Nothing", Toast.LENGTH_LONG).show();
}
}

@Override
protected void onPreExecute()
{
}

}

public String getInput(final String title, final String errorMessage, final Context cc)
{
runOnUiThread(runnable = new Runnable()
{
@Override
public void run()
{
AlertDialog.Builder builder = new AlertDialog.Builder(cc);
//customize alert dialog to allow desired input
builder.setTitle(title);
builder.setMessage(errorMessage);
// builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
dInput = "YES";
synchronized(runnable)
{
runnable.notify();
}
Toast.makeText(cc, "I am in after yes runnable notify", Toast.LENGTH_LONG).show();
// return;
}
})
similary code for no and cancel buttons
});
alert = builder.create();
alert.show();
Toast.makeText(cc, "I am in after show alert", Toast.LENGTH_LONG).show();
}
});

try
{
synchronized (this)
{
wait();
}
}
catch (InterruptedException e)
{
}
return dInput;
}


The problem i am having with this code is, the callalert is called but does not wait for user input. The rest of the code after the callalert is executed without waiting for your input on the dialog.
Also the onPostExceute method does not get executed.

Appreciate any help on this.

Thanks in advance for your help.

Vijiya

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingAndroid Development > How to make AlertDialog wait for user input?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap