I am new to android studio.i have a simple question. I want my btnsave works only when there is somthing in editText. First,when application lunched, when there is not anything in editText my code works(btnsave does not work).But when i type sth in editText i expects btnsave can be able to work.but NO! it doesnt work.i think if statment only runs one time.
What is the problem ?! I want this code run permanently while the application is running.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSave = (Button) findViewById(R.id.btnSave);
editText = (EditText) findViewById(R.id.editText);
if (!editText.getText().toString().matches(""))
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"H", Toast.LENGTH_SHORT).show();
}
});
}
Aucun commentaire:
Enregistrer un commentaire