Android 按下对话框中的关闭按钮时出错
按下其中一个菜单按钮时,我已创建了对话框:Android 按下对话框中的关闭按钮时出错,android,dialog,Android,Dialog,按下其中一个菜单按钮时,我已创建了对话框: @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_first__window, menu); return true; } @Override
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_first__window, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id)
{
case R.id.action_settings:
About_us aboutus = new About_us(this);
aboutus.show();
return true;
case R.id.close: System.exit(0); return true;
}
return super.onOptionsItemSelected(item);
}
我的对话框布局
<Button
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Close"
android:onClick="ext_btn"/>
我尝试了很多代码使关闭按钮关闭对话框。
我的应用程序总是崩溃。
错在哪里 试试这个
Button btn_ext = (Button) findViewById(R.id.btn_ext);
btn_ext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
我已尝试:system.exit(0);使用finish()而不是System.exit(0)已使用它。它不起作用。当我按下后退按钮时,它工作正常
Button btn_ext = (Button) findViewById(R.id.btn_ext);
btn_ext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});