我有主要活动和一个简单的类。主要活动有对话框方法,我从另一个类调用此方法
主要活动-
public class WishareActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activity=this;
//handler to call alertmsg()method
alerthandler= new Handler() {
public void handleMessage(Message msg){
alertmsg();
}
};
layouthandler= new Handler() {
public void handleMessage(Message msg){
setContentView(R.layout .main);
}
};
}
//method to show the dialog box
public static void alertmsg()
{
AlertDialog.Builder alert = new AlertDialog.Builder(WishareActivity.activity);
alert.setTitle("Confirm");
alert.setMessage("abc");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
alert.setNegativeButton("Deny", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
Log.d("abc","alert alert");
AlertDialog s=alert.create();
s.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface dialog) {
}
});
Log.d("abc1","alert alert");
alert.show();
Log.d("abc1","alert alert alert");
return;
}
连接类
public class connect implements Runnable
{
public void run()
{
WishareActivity.layouthandler.sendEmptyMessage(0);
WishareActivity.alerthandler.sendEmptyMessage(0);
}
}
在 Logcat 中它的显示
abc : alert alert
abc1: alert alert
abc1 :alert alert alert
根据日志,该方法被正确调用,但没有显示对话框。
任何帮助将不胜感激