It is impossible to display the text in the dialog box taken from resources, instead of it there are numbers 2131230764. At the same time, if you remove the getDate() code from the code, the text is displayed correctly.

 AlertDialog.Builder adb = new AlertDialog.Builder(this); // заголовок adb.setTitle("Заголовок"); // сообщение adb.setMessage(R.string.text1+getDate()+"text2"); // иконка adb.setIcon(android.R.drawable.ic_dialog_info); // кнопка положительного ответа adb.setPositiveButton("Да", myClickListener); // кнопка отрицательного ответа adb.setNegativeButton("Нет", myClickListener); 

enter image description here

    1 answer 1

    R.string.text1 is a resource identifier (in this case, a string), it is of type int (that is, it is just an integer).

    The AlertDialog.Builder class contains two setMessage(...) methods with different signatures:

    The first:

     setMessage(int messageId) 

    This method accepts a resource (text) identifier. That is, in your case, you can do this:

     adb.setMessage(R.string.text1); 

    Second:

     setMessage(CharSequence message) 

    This method accepts an object that implements the CharSequence interface.

    In your case:

     adb.setMessage(R.string.text1 + getDate() + "text2"); 

    the second method is used and, in this case, an implicit conversion of R.string.text1 from int to String occurs, whence we get the number in the string - this is the identifier of the resource.

    To display the text, you need to use the method that returns the resource by the resource identifier, in this case it can be implemented, for example, like this:

     String text1 = YourActivity.this.getResources().getString(R.string.text1); adb.setMessage(text1 + getDate() + "text2"); 
    • earned, thanks! - Alexander