[Android]editText view with alert 結合多重按鈕事件
import:
源代碼:
使用:
※引入的view為(View view)的view
1 2 3 | import android.app.AlertDialog; import android.content.DialogInterface; import android.widget.EditText; |
源代碼:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | public void EditValue(final View view){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("數量"); builder.setCancelable(false); final EditText input1 = new EditText(this); input1.setText("DEFAULT TEXT"); builder.setView(input1); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //My code switch(view.getId()) { case R.id.CKA: Log.d(TAG, "SETA"); break; case R.id.CKB: Log.d(TAG, "SETB"); break; case R.id.CKC: Log.d(TAG, "SETC"); break; case R.id.CKD: Log.d(TAG, "SETD"); break; case R.id.CKE: Log.d(TAG, "SETE"); break; } } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } |
使用:
1 | EditValue(view); |
留言
張貼留言