package com.example.alertdialog;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
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 SampleClickListener());
}
class SampleClickListener implements OnClickListener{
public void onClick(View v){
new AlertDialog.Builder(MainActivity.this)
.setTitle("購買")
.setMessage("謝謝惠顧")
.setPositiveButton("確定",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;
}
}
留言列表