这是我的活动,其中我有对话框的代码......我想做的是,当用户按下按钮时,必须出现一个对话框,询问用户是否要将该链接保存在数据库中。
public class Add_ink extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.websearch);
Button btn = (Button) findViewById(R.id.add_link);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(0);
}
});
}
@Override
protected Dialog onCreateDialog(int id){
switch (id){
case 0:
return new AlertDialog.Builder(this)
.setIcon(R.drawable.help_ov)
.setTitle("This is a dialog with simple text")
.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(getBaseContext(), "OK Clicked", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(getBaseContext(), "Cancel Clicked", Toast.LENGTH_SHORT).show();
}
})
.create();
}
return null;
}
}