Android Studio Поделиться текстом из AlertDialog - PullRequest
0 голосов
/ 03 июня 2018

Я хочу отправить свой результат в alerttdialog мессенджеру или любому другому приложению.

Это мой AlertDialog:

enter image description here

Это мой код.

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Result");
alertDialogBuilder
        .setMessage("\nڕیكه‌وت : " + year + "/" + month + "\n\nكۆی خه‌رجی : " + a + "\n\nكۆی نرخی : " + b + " دینار")
        .setCancelable(false)
        .setPositiveButton("Send Result",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // Write Code Here For Send Result
                    }
                })

        .setNegativeButton("Done", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

                dialog.cancel();
            }
        });

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();

1 Ответ

0 голосов
/ 03 июня 2018

Насколько я понимаю, вы в основном делитесь текстом с другими приложениями.В этом случае, эта простая реализация сделает работу, я надеюсь.

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Result");
alertDialogBuilder
        .setMessage("\nڕیكه‌وت : " + year + "/" + month + "\n\nكۆی خه‌رجی : " + a + "\n\nكۆی نرخی : " + b + " دینار")
        .setCancelable(false)
        .setPositiveButton("Send Result",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                        // Will create a share picker to share the text among applications installed in your phone
                        Intent sendIntent = new Intent();
                        sendIntent.setAction(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
                        sendIntent.setType("text/plain");
                        startActivity(sendIntent);

                    }
                })

        .setNegativeButton("Done", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

                dialog.cancel();
            }
        });

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();

Вы можете также изучить документацию разработчика здесь , чтобы узнать больше об этом.

...