I have a button action, when the user clicks the button, an AlertDialog appears with 2 EditText, where you enter the email address and password to enter. When I try to get text from EditText, I always get only empty lines. The login_alert layout is the AlertDialog layout. Here is the code:
View view = getLayoutInflater().inflate(R.layout.login_alert, null, false); String email = ((EditText) view.findViewById(R.id.emailEditText)).getText().toString(); String password = ((EditText) view.findViewById(R.id.passwordEditText)).getText().toString(); System.out.println("DEBUG: "+email+", "+password);
EDIT: Activity Code:
public class MainActivity extends FragmentActivity { public static final String mAPP_ID = "..."; public static final String USER_DB_URL = "..."; AssetsExtracter mTask; private MainFragment mainFragment; private List<User> usersList = new ArrayList<User>(); private User currentUser = null; private Button labLoginButton; private EditText emailET; private EditText passwordET; private ProgressDialog dialog; private View alertView; boolean userIsLogged = false; static { IMetaioSDKAndroid.loadNativeLibs(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_main); alertView = getLayoutInflater().inflate(R.layout.login_alert, null, false); emailET = (EditText) view.findViewById(R.id.emailEditText); passwordET = (EditText) view.findViewById(R.id.passwordEditText); labLoginButton = (Button) findViewById(R.id.loginLabButton); updateLoginButton(); dialog = new ProgressDialog(this); dialog.setMessage("Signin in..."); if (savedInstanceState == null) {
SOLVING THE PROBLEM, SOLUTION: In onCreate (), I inflate the alert_dialog layout in the View variable. I made a variable of the form View global (before onCreate ()) and then in onLabLoginButtonClick () I do not inflate the view again, but I use this global instance in onCreate (). hope this is clear. Thank you all!
android string android-edittext
Cardella
source share