Note that there are some explanatory texts on larger screens.

plurals
  1. POvalidate the edittext field inside alertdialog
    primarykey
    data
    text
    <p>I am using this function to insert into the database. I'd like to validate inputs from two edittext fields. Whenever I push ok button without giving any inputs, the program crashes.I tried to print the values as well, but it didnt display in logcat.Am i doing anything wrong?</p> <pre><code> private void add() { LayoutInflater inflater=LayoutInflater.from(this); final View addView=inflater.inflate(R.layout.add_country, null); new AlertDialog.Builder(this) .setTitle("Add new country/year") .setView(addView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClickDialogInterface dialog,int whichButton) { /* Read alert input */ EditText editCountry =(EditText)addView.findViewById(R.id.editCountry); String country = editCountry.getText().toString(); EditText editYear =(EditText)addView.findViewById(R.id.editYear); int year = Integer.parseInt( editYear.getText().toString() ); if(editCountry.getText().toString().trim().length()&gt;0 &amp;&amp; editYear.getText().toString().trim().length()&gt;0){ /* Open DB and add new entry */ db.open(); db.insertEntry(country,year); /* Create new cursor to update list. Must be possible to handle * in a better way. */ entryCursor = db.fetchAllEntries(); // all country/year pairs adapter = new SimpleCursorAdapter(CountryEditor.this, R.layout.country_row,entryCursor, new String[] {"country", "year"}, new int[] {R.id.country, R.id.year}); setListAdapter(adapter); db.close(); } else{ Toast.makeText(CountryEditor.this, "You need to enter Country AND Year.", Toast.LENGTH_LONG).show(); } } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { // ignore, just dismiss } }) .show(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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