My goal is to get an input at the edit-text fields. The idea was to disable the 'submit' button as long as the user didn't enter all the details. However I got a problem while trying to do so.
I do not have problem with the Intent or the screens.
The code:
public class Welcome extends Activity
{
EditText efn,eln,eage;
Button submit;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
efn=(EditText)findViewById(R.id.fname);
eln=(EditText)findViewById(R.id.lname);
eage=(EditText)findViewById(R.id.age);
submit=(Button)findViewById(R.id.submit);
submit.setEnabled(CheckIfOkInput());
// I guess the problem is over here <--
if(CheckIfOkInput()==false)
{
while(CheckIfOkInput())
{
efn=(EditText)findViewById(R.id.fname);
eln=(EditText)findViewById(R.id.lname);
eage=(EditText)findViewById(R.id.age);
}
submit.setEnabled(true);
}
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent iHome=new Intent (Welcome.this,Home_page.class);
String ln=eln.getText().toString();
String fn=efn.getText().toString();
int age=Integer.valueOf (eage.getText().toString());
iHome.putExtra("fname", fn);
iHome.putExtra("lname", ln);
iHome.putExtra("age", age);
startActivity(iHome);
}
});
}
public boolean CheckIfOkInput()
{
if(this.eln.getText().toString()==""||this.efn.getText().toString()=="")
{
return false;
}
return true;
}
}
And the result of this code is that the Submit button just keep being disabled forever.
Hope you guys could help me with that.
Thanks in advance,
Yaniv.