close
package vision.google.com.camera; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.EditText; import util.ToastUtil; public class DialogActivity extends AppCompatActivity { private Button mBtnDialog1,mBtnDialog2,mBtnDialog3,mBtnDialog4,mBtnDialog5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); mBtnDialog1 = (Button) findViewById(R.id.btn_dialog1); mBtnDialog2 = (Button) findViewById(R.id.btn_dialog2); mBtnDialog3 = (Button) findViewById(R.id.btn_dialog3); mBtnDialog4 = (Button) findViewById(R.id.btn_dialog4); mBtnDialog5 = (Button) findViewById(R.id.btn_dialog5); OnClick onClick = new OnClick(); mBtnDialog1.setOnClickListener(onClick); mBtnDialog2.setOnClickListener(onClick); mBtnDialog3.setOnClickListener(onClick); mBtnDialog4.setOnClickListener(onClick); mBtnDialog5.setOnClickListener(onClick); } class OnClick implements View.OnClickListener { @Override public void onClick (View v) { switch(v.getId()) { case R.id.btn_dialog1: AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this); builder.setTitle("Please Answer").setMessage("Hello,Eric") .setIcon(R.drawable.icon_checkbox_true) .setPositiveButton("棒", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,"你很誠實"); } }) .setNeutralButton("還行", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,"你在橋橋"); } }) .setNegativeButton("不行", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,"Fuck you"); } }).show(); break; case R.id.btn_dialog2: final String [] array2 = new String[]{"男","女","中性"}; AlertDialog.Builder builder1 = new AlertDialog.Builder(DialogActivity.this); builder1.setTitle("選擇性別").setItems(array2, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,array2[i]); } }).show(); break; case R.id.btn_dialog3: final String [] array3 = new String[]{"男","女","中性"}; AlertDialog.Builder builder3 = new AlertDialog.Builder(DialogActivity.this); builder3.setTitle("選擇性別").setSingleChoiceItems(array3, 1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,array3[i]); dialogInterface.dismiss(); } }).setCancelable(false).show(); break; case R.id.btn_dialog4: final String [] array4 = new String[]{"唱歌","跳舞","Coding"}; boolean [] isSelected = new boolean[]{false,false,true}; AlertDialog.Builder builder4 = new AlertDialog.Builder(DialogActivity.this); builder4.setTitle("選擇興趣").setMultiChoiceItems(array4, isSelected, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i, boolean b) { ToastUtil.showMsg(DialogActivity.this,array4[i]+":"+b); } }).setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,"Button :OK"); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ToastUtil.showMsg(DialogActivity.this,"Button :Cancel"); } }).show(); break; case R.id.btn_dialog5: AlertDialog.Builder builder5 = new AlertDialog.Builder(DialogActivity.this); View view = LayoutInflater.from(DialogActivity.this).inflate(R.layout.layout_dialog,null); EditText etUserName = (EditText) view.findViewById(R.id.et_userName); EditText etPassword = (EditText) view.findViewById(R.id.et_password); Button btnLogin = (Button) view.findViewById(R.id.btn_login); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ToastUtil.showMsg(DialogActivity.this,"Click OK"); } }); builder5.setTitle("Please Sign in").setView(view).show(); break; } } } }
全站熱搜
留言列表