开发者

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜