how to create an Alert Dialogu in Android without onCliclkListener
I wanted to display an Alert Dialogue inside thread or alternatively such a way that AlertDialogue opens up directly after finding some records in database negative, w/o clicking on any button.. Alert dialogue may contain Few 开发者_开发百科lines and 2-3 buttons..
referred following link and tried on my own but not getting how to create an AlertDialogue without using onClickListener as its working with it(onClickListener) very smoothly:
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Thanks in Advance.
public class jar_layut extends Activity {
/** Called when the activity is first created. */
boolean out=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new Runnable()
{ public void run()
{
try {
out=first_check_pic_on_device();
mHandlerMySpace5.post(mUpdateResultsMySpace5);
} catch (Exception e) {
// TODO Auto-generated catch block
mHandlerMySpace5.post(mUpdateResultsMySpace5);
}
}
} ).start();
}
private boolean first_check_pic_on_device()
{
Context contextMySpace= this;;
try {
FileInputStream stream =contextMySpace.openFileInput("prf.png");
try {
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
return false;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
return false;
}
}
final Handler mHandlerMySpace5 = new Handler();
final Runnable mUpdateResultsMySpace5 = new Runnable() {
public void run() {
if(!out)
{
showDialog();
}
}
};
private void showDialog()
{
final CharSequence[] items = {"one", "two"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(item==0)
{
}
if(item==1)
{
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
check out the below link http://developer.android.com/guide/topics/ui/dialogs.html ---> expand(click) on "Example ProgressDialog with a second thread". This will solve your problem.
精彩评论