package com.example.alertdialog2;

import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivity extends Activity {
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);

bt = new Button(this);
bt.setText("購買");

ll.addView(bt);

bt.setOnClickListener(new clickListener());
}

class clickListener implements OnClickListener{
public void onClick(View v){
AlertDialog.Builder checkme = new AlertDialog.Builder(MainActivity.this);
checkme.setTitle("確認");
checkme.setMessage("請再次確認是否購買??");
checkme.setNegativeButton("不要", null);
checkme.setNeutralButton("取消", null);
checkme.setPositiveButton("要",new myDialogClickListener()).show();

}

}
class myDialogClickListener implements DialogInterface.OnClickListener{
public void onClick(DialogInterface d, int w){
new AlertDialog.Builder(MainActivity.this)
.setTitle("購買")
.setMessage("謝謝惠顧")
.setPositiveButton("OK", null).show();
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

arrow
arrow

    痞客興 發表在 痞客邦 留言(0) 人氣()