Categories
Android

Android

在XML布局中 为组件指定id 从而在程序中进行操作

<TableRow

android:id=”@+id/allocation_table_row”>

 

监听返回键

[cce lang=”java”]

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { // listen the back key
this.exitDialog();
}
return false;
}

private void exitDialog() {
Dialog dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle(“Exit”)
.setMessage(“Are you sure want to exit?”)

.setPositiveButton(“Yes”,
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,
int which) {
MainActivity.this.finish(); // finish the
// activity
}
})
.setNegativeButton(“No”, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}
}).create(); // create the dialog
dialog.show(); // show the dialog
}

[/cce]

Leave a Reply

Your email address will not be published. Required fields are marked *