R.string.**+string causes the number to appear in the R.string.** part.

Asked 2 years ago, Updated 2 years ago, 36 views

In order to create a Dialog that prompts Android (Java) to update the app, we have implemented the following code:

VersionCode is the version obtained from PackageInfo. The latest_version is the latest version obtained from Json

AlertDialog.Builder UpdateDialog=newAlertDialog.Builder(MainActivity.this);
UpdateDialog.setTitle("UPDATE!");
UpdateDialog.setMessage(R.string.update+"\nYOURVERSION:"+versionCode+"\nLATESTVERSION:"+latest_version);
UpdateDialog.setIcon(R.mipmap.ic_launcher);
UpdateDialog.setCancelable(false);
UpdateDialog.setPositiveButton("UPDATE", newDialogInterface.OnClickListener(){
    @ Override
    public void onClick (DialogInterface dialog, int which) {
        dialog.dismiss();
        setState(PREFERENCE_BOOTED);
    }
});
UpdateDialog.create();
UpdateDialog.show();

Dialog then has

UPDATE

2131230759
YOUR_VERSION: 1
LATEST_VERSION: 3.1

he said.
It probably doesn't seem to work when displaying R.string.

If anyone knows how to solve this problem, please let me know.

java android

2022-09-30 17:21

1 Answers

I'm sorry.Self-resolved.

getResources().getString(R.string.update) to get the string instead of int.

Modified code

AlertDialog.Builder UpdateDialog=newAlertDialog.Builder(MainActivity.this);
// set title
UpdateDialog.setTitle("UPDATE!");
String update = getResources().getString(R.string.update);
UpdateDialog.setMessage(update+"\nYOURVERSION:"+versionName+"\nLATESTVERSION:"+latest_version); // set content
UpdateDialog.setIcon(R.mipmap.ic_launcher); // set icon
UpdateDialog.setCancelable(false);
UpdateDialog.setPositiveButton("UPDATE", newDialogInterface.OnClickListener(){
    @ Override
    public void onClick (DialogInterface dialog, int which) {
        dialog.dismiss();
        download();
    }
});
UpdateDialog.create();
UpdateDialog.show();


2022-09-30 17:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.