저는 주 활동이 시작되어 연락처 목록을 채우고 모든 연락처 (promptUserForInput)에 대한 현재 등급을 묻는 메시지를 표시하고 모든 연락처의받은 평가를 즉시 처리해야한다는 안드로이드 애플 리케이션을 작성하고 있습니다. 모든 대화 상대를 알리는 대화 상자를 사용할 수 있고 사용자의 평점을받을 수 있다고 생각했습니다. 그러나 주 스레드가 사용자가 모든 사용자의 등급 입력을 마칠 때까지 기다리지 않아 코드 아래에서 오류가 발생합니다.사용자가 루프에서 텍스트 입력을 요구하는 방법?
다음은 모든 연락처 이름에 대해 do while 루프의 주 활동에서 호출하는 내 함수입니다. rating은 전역 변수입니다.
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();
}
이 promptUserForInput()
의 발신자는 다음과 같습니다.
// get list of contacts in a cursor
Cursor cursor = ManageDataBaseActivity.queryDataBase(this,
ManageDataBaseActivity.CONTACT_INFO_TABLE);
if(cursor.getCount()>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());