如何在AlertDialog中添加多个EditText对象

时间:2018-01-29 03:32:16

标签: android-studio android-alertdialog

我正在尝试添加第二个空白,以便用户在警告对话框的第二个文本框中输入第二个文本,我该怎么做?我试图直接添加一个文本框,但这样做只会替换用户在出现警告对话框时读取的当前文本,而且我的第二个文本框也不会出现

这是我目前的代码

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_add_task:

            final EditText taskEditText = new EditText(this);
            AlertDialog dialog = new AlertDialog.Builder(this)
                    .setTitle("Add a new task")
                    .setMessage("What do you want to do next?")
                    .setView(taskEditText)
                    .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String task = String.valueOf(taskEditText.getText());
                            SQLiteDatabase db = mHelper.getWritableDatabase();
                            ContentValues values = new ContentValues();
                            values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task);
                            db.insertWithOnConflict(TaskContract.TaskEntry.TABLE,
                                    null,
                                    values,
                                    SQLiteDatabase.CONFLICT_REPLACE);
                            db.close();
                            updateUI();
                        }
                    })
                    .setNegativeButton("Cancel", null)
                    .create();
            dialog.show();
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}

2 个答案:

答案 0 :(得分:0)

创建vector2并将permutation_number = 10000 for(j in 1:permutation_number){ vector1 <- c() vector2 <- c() for(i in 1:5){ for(z in 1:5){ #Print number of genes to sample number_of_rows <- length(which(df1$SizeQuintile == i & df1$ExpressionQuintile == z)) #Extract value from every combination of quintiles, append to vector vector1 <- append(vector1, df1[which(df1$SizeQuintile == i & df1$ExpressionQuintile == z), ]$Type1) vector2 <- append(vector2, df2[sample(which(df$SizeQuintile == i & df2$ExpressionQuintile == z), number_of_rows), ]$Type1) } } #Compare medians, then append resulting TRUE or FALSE value to a #vector. vector3 <- append(vector3, median(vector1) > median(vector2)) } #Compute p value vector3/permutation_number 添加到其中

LinearLayout

答案 1 :(得分:0)

val alert = AlertDialog.Builder(context)
    alert.setTitle("Buy Airtime")
    alert.setMessage("Enter phone details and amount to buy airtime.")

    val layout = LinearLayout(context)
    layout.orientation = LinearLayout.VERTICAL

    val mobileNoET = EditText(context)
    mobileNoET.setSingleLine()
    mobileNoET.hint = "Mobile Number"
    layout.addView(mobileNoET)

    val amountET = EditText(context)
    amountET.setSingleLine()
    amountET.hint = "Amount"
    layout.addView(amountET)

    val networkET = EditText(context)
    networkET.setSingleLine()
    networkET.hint = "Network"
    layout.addView(networkET)

    layout.setPadding(50, 40, 50, 10)

    alert.setView(layout)

    alert.setPositiveButton("Proceed") { _, _ ->
        val mobileNo = mobileNoET.text.toString()
        val amount = amountET.text.toString()
        val network = networkET.text.toString()

        Log.i("xxx",mobileNo )
        Log.i("xxx",amount )
        Log.i("xxx",network )
    }

    alert.setNegativeButton("Cancel") { dialog, _ ->
        dialog.dismiss()
    }

    alert.setCancelable(false)
    alert.show()