Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to prompt user for text input in a loop?
    text
    copied!<p>I am writing an android app in that main activity starts and populates a list of contacts, and needs to prompt the user for today's rating of all the contacts(promptUserForInput) and immediately process received rating of all the contacts. I thought i can use a dialogue box that prompt for every contact and gets the rating from the user. But below code fails as the main thread is not waiting for the user to finish enter rating of all the users.</p> <p>Here is my function which I am calling in the main activity in a do while loop for all the contact names. rating is a global variable.</p> <pre><code>double rating=0; private synchronized void promptUserForInput(String firstName, String lastName) { final String fname = firstName; final String lName = lastName; AlertDialog.Builder alert = new AlertDialog.Builder(this); String custName = firstName + " " + lastName; final EditText input = new EditText(this); alert.setTitle(custName); alert.setView(input); Log.v("Diva: in promptUserForInput", "setting positive buton"); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { Editable res = input.getText(); if(res == null) { Log.v("Diva..", "In positivebutton..befoer getting rating res is null"); } rating = Double.valueOf(input.getText().toString()); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { rating=0; } }); alert.show(); } </code></pre> <p>My caller of this <code>promptUserForInput()</code> looks like below.</p> <pre><code>// get list of contacts in a cursor Cursor cursor = ManageDataBaseActivity.queryDataBase(this, ManageDataBaseActivity.CONTACT_INFO_TABLE); if(cursor.getCount()&gt;0) { double totalRatingForStats=0; cursor.moveToFirst(); do { String[] colNames = cursor.getColumnNames(); Log.v("Diva Colum names = ", colNames[0] + " " + colNames[1] + " " + colNames[2] + " " + colNames[3]); String firstName = cursor.getString(cursor.getColumnIndex("FirstName")); Log.v("Diva ..:", firstName); String lastName = cursor.getString(cursor.getColumnIndex("LastName")); String key = ManageDataBaseActivity.getDbKey(firstName, lastName, date, ManageDataBaseActivity.CUSTOMER_DATA_TABLE); promptUserForInput(firstName, lastName); double ratingReceived = rating; totalRatingForStats = totalRatingForStats+ratingReceived; // some more processing ManageDataBaseActivity.insertValueToDB(ManageDataBaseActivity. CONTACT_DATA_TABLE+" ", .....); } while(cursor.moveToNext()); </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