В приведенном ниже коде вы можете объяснить мне, почему блок внутри оператора if выполняется до вызова метода request_user_name()? Результат ниже кода заключается в следующем:Почему мой код не выполнен в правильном порядке?
Я внутри если заявление
Я вне если заявление
request_user_name() называется - OK щелкнул
chatbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(request_user_name())
{
System.out.println("I am inside the if statement");
Intent intent = new Intent(MainActivity.this, ChatRoom.class);
intent.putExtra("room_name", "room");
intent.putExtra("user_name", name);
startActivity(intent);
}
System.out.println("I am outside the if statement");
}
});
private Boolean request_user_name() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Enter Name:");
final EditText input_filed = new EditText(this);
builder.setView(input_filed);
final Holder<Boolean> accessChatRoom = new Holder<Boolean>(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
name = input_filed.getText().toString();
System.out.println("request_user_name() called - OK clicked");
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
System.out.println("request_user_name() called - Cancel clicked");
accessChatRoom.setValue(false);
}
});
builder.show();
return accessChatRoom.getValue();
}
Что такое 'request_user_name'? – Moira
Отправьте весь код –
request_user_name() Возвращает «true». Отправьте код метода. –