activity_student_detail.xml:
<RelativeLayout
android:width="match_parent"
android:height="wrap_content"
android:background="@android:color/holo_blue_bright">
<Button
android:id= "@+id/btnBack"
android:centerVertical="true"
android:text="返回"
android:width="wrap_content"
android:height="wrap_content"/>
<TextView
android:width="wrap_content"
android:height="wrap_content"
android:text="学生详细信息"
android:textSize="20sp"
android:centerVertical="true"
android:centerHorizontal="true"/>
</RelativeLayout>
this.findViewById(R.id.btnBack).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
StudentDetailActivity.this.finish();
}
});
ListViewDemo1Activity.java:
@Override
public boolean onKeyUp(int keyCode,KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_BACK){
AlterDialog.Builder builder = new AlterDialog.Builder(ListViewDemo1Activity.this);
builder.setTitle("温馨提示");
builder.setMessage("你确定是否退出");
builder.setPositiveButton("确定",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which){
ListViewDemo1Activity.this.finish();
}
});
builder.setNegativeButton("否定",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog,int which){
}
});
builder.show();
}
return false;
}