提示按下按钮

时间:2017-03-17 04:47:36

标签: android prompt

我目前正致力于让用户注册并输入他/她的详细信息的应用程序。我想要显示“成功注册!”用户按下提交按钮后的提示或消息,以便用户知道他/她输入的详细信息已提交。

这是我的提交按钮:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        Intent recvdIntent = getIntent();
        mUsername = recvdIntent.getStringExtra("USERNAME");
        mUsername = recvdIntent.getStringExtra("PASSWORD");

        Button btnSubmit = (Button) findViewById(R.id.btn_submit);
        btnSubmit.setOnClickListener(

                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        submitUserData();
                        return;
                        }
        }
    );

3 个答案:

答案 0 :(得分:3)

<强> AlertDialog

public void showAlertDialog(String title,String msg){


    AlertDialog alertDialog = new AlertDialog.Builder(
            AlertDialogActivity.this)
            .setTitle(title)  // Setting Dialog Title
            .setMessage(msg)// Setting Dialog Message
            .setCancelable(false)
            .create();

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog closed
                Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                }
        });


    // Showing Alert Message
    alertDialog.show();

}

<强>吐司。

public static void showToast(Context context,String msg){

        Toast.makeText(context,msg,Toast.LENGTH_LONG).show();
    }

答案 1 :(得分:1)

试试这个:

final AlertDialog.Builder builder = new AlertDialog.Builder(SignupActivity.this);
builder.setCancelable(false);
builder.setTitle("Success");
builder.setMessage("Successfully registered, Sign in now");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Intent intent = new Intent(SignupActivity.this, TargetActivity.class);
        startActivity(intent);
        finish();
    }
});
builder.show();

答案 2 :(得分:1)

你可以采取多种方式,

  1. 提醒对话
  2. Toast
  3. 弹出对话
  4. 让我们使用警报对话框。

    AlertDialog alertDialog = new AlertDialog.Builder(
                            AlertDialogActivity.this).create();
    
            // Setting Dialog Title
            alertDialog.setTitle("Alert Dialog");
    
            // Setting Dialog Message
            alertDialog.setMessage("Welcome");
    
            // Setting Icon to Dialog
            alertDialog.setIcon(R.drawable.tick);
    
            // Setting OK Button
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to execute after dialog closed
                    Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                    }
            });
    
            // Showing Alert Message
            alertDialog.show();