displaying a dialogbox on click of a button in android
how can we display a dialogbox on cl开发者_运维知识库ick of a button in android??
If you want to create Alert Dilaog in android when your Button is touched, pls see this
findViewById(R.id.myButton).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
displayAlert();
retrun false;
}
}
public void displayAlert()
{
new AlertDialog.Builder(this).setMessage("Hi , I am Alert Dialog")
.setTitle("My Alert")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
}
Try this in android manifest.Any activity you can create a dialog box using theme.dialog in android manifest.
<activity android:name=".your_activity" android:theme="@android:style/Theme.Dialog" />
hope this ll help you all guys..
精彩评论