Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display an alertdialog on top of other alertdialog? And when one in foreground is closed, then the one in background should be visible
    text
    copied!<p>This is my code to edit/update which I am doing throgh a custom alertdialog which contains the data fetched frm database. Now when the inputs provided are incorrect I want to show other alertdialog on top of this providing some message to user. When the user dismisses this message alertdialog, the previous one which is used for update should be visible. How can I do that?</p> <pre><code>public class CountryEdit extends ListActivity{ private Long mRowId; private CountryDbAdapter mDbHelper; public static final String PROVIDER_NAME = "assignment2.demos.MyCountriesCP"; public static final String uriString = "content://"+ PROVIDER_NAME +"/countries"; public static final Uri CONTENT_URI = Uri.parse(uriString); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ContentResolver contentResolver = getContentResolver(); Cursor c = contentResolver.query(CONTENT_URI, null, null, null, getIntent().getExtras().getString("SORT_ORDER")); String[] from = new String[] { "year", "country" }; int[] to = new int[] { R.id.year, R.id.country }; SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.country_row, c, from, to); setListAdapter(sca); mRowId = savedInstanceState != null ? savedInstanceState.getLong(assignment2.demos.MyCountriesActivity.KEY_ROWID) : null; if (mRowId == null) { Bundle extras = getIntent().getExtras(); mRowId = extras != null ? extras.getLong(assignment2.demos.MyCountriesActivity.KEY_ROWID) : null; } populateFields(); } private void populateFields() { LayoutInflater inflater=LayoutInflater.from(this); final View addView=inflater.inflate(R.layout.add_country, null); Cursor c = getContentResolver().query(CONTENT_URI.buildUpon(). appendPath(String.valueOf(mRowId)).build(), null, null, null, null); /* Read alert input */ final EditText editCountry =(EditText)addView.findViewById(R.id.editCountry); final EditText editYear =(EditText)addView.findViewById(R.id.editYear); editCountry.setText(c.getString(c.getColumnIndex("country"))); editYear.setText(c.getString(c.getColumnIndex("year"))); new AlertDialog.Builder(this) .setTitle("Edit country/year") .setView(addView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { String country = editCountry.getText().toString(); if(country.trim().length()&gt;0 &amp;&amp; editYear.getText().toString().trim().length()&gt;0){ int year = Integer.parseInt(editYear.getText().toString()); ContentValues updateValues = new ContentValues(); updateValues.put(mDbHelper.COUNTRY, country); updateValues.put(mDbHelper.YEAR, year); getContentResolver().update( CONTENT_URI.buildUpon().appendPath(String.valueOf(mRowId)).build(), updateValues, null, null); finish(); } else{ new AlertDialog.Builder(CountryEdit.this) .setTitle("Invalid Inputs!") .setMessage("You need to enter Country AND Year.") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions finish(); } }).show(); // Toast.makeText(CountryEdit.this, // "You need to enter Country AND Year.", Toast.LENGTH_LONG).show(); //finish(); } } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { // ignore, just dismiss finish(); } }) .show(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload