For my old project YahrtzeitZmanim I needed to add start-up alert box, which will announce new version of Yahrtzeit2 app.
For these purposes, I added the following code to onCreate function:
AlertDialog.Builder adb=new AlertDialog.Builder(TabView.this); LayoutInflater adbInflater = LayoutInflater.from(TabView.this); View eulaLayout = adbInflater.inflate(R.layout.checkbox, null); dontShowAgain = (CheckBox)eulaLayout.findViewById(R.id.skip); adb.setView(eulaLayout); adb.setTitle("Attention"); adb.setMessage(Html.fromHtml("This version is going to be depricated soon.
" + "Get Yahrtzeit2 in case you want to store your own Yahrtzeit dates
" + "Do you want to get Yahrtzeit2?")); adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String checkBoxResult = "NOT checked"; if (dontShowAgain.isChecked()) checkBoxResult = "checked"; SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("skipMessage", checkBoxResult); // Commit the edits! editor.commit(); startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.mb.yartzeit2"))); return; } }); adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String checkBoxResult = "NOT checked"; if (dontShowAgain.isChecked()) checkBoxResult = "checked"; SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("skipMessage", checkBoxResult); // Commit the edits! editor.commit(); return; } }); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); String skipMessage = settings.getString("skipMessage", "NOT checked"); if (!skipMessage.equalsIgnoreCase("checked") ) adb.show();
and before onCreate function some pre-requisites:
public static final String PREFS_NAME = "MyPrefsFile1"; public CheckBox dontShowAgain;
Additionally, I needed to create layout for checkbox.xml
Thanx
🙂
You should never compare strings with !=
Right, corrected the code.
And it should be !equals… instead of equals… 🙂
Best regards
fixed 😉
It’s need to fix “linearlayout” in xml to “Linearlayout
Hi,
Thank you for outlining it.
Seems it is the problem of the plugin, which highlights the code. Original code is correct.
sorry! this is correct —> LinearLayout
I think checkbox need to fix below
Very helpful; thanks!