我从我的自定义视图扩展View.有3个视图构造函数:
View(Context context, AttributeSet attrs, int defStyle)View(Context context, AttributeSet attrs)View(Context context)从我的活动我打电话std.setContentView(R.layout.main).第二个构造函数在我的视图中被调用.为什么第二个?如何预先知道哪一个将被调用以及为什么?
我试图用OK按钮显示一个消息框.我为此目的使用AlertDialog,我意识到它没有阻止代码.例:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new AlertDialog.Builder(this).setTitle("Test dlg").setMessage("Alert 1")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
})
.setNegativeButton("", null)
.show();
new AlertDialog.Builder(this).setTitle("Test dlg").setMessage("Alert 2")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
})
.setNegativeButton("", null)
.show();
//...continue with UI initialization here...
}
Run Code Online (Sandbox Code Playgroud)
当我开始活动时,它会显示Alert2,当我按下确定后,它会显示Alert1.
我需要有阻止代码对话框,所以首先它应该显示Alert1消息,等到用户按下OK按钮然后继续执行代码并显示Alert2消息等.示例:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
msgBox("Test dlg", "Alert 1");
msgBox("Test dlg", "Alert 2");
//...continue with UI initialization here...
}
private void msgBox(String …Run Code Online (Sandbox Code Playgroud)