I need to know that how can i take value from an edit text field without pressing button..i.e I need to change the content of another text field as soon as user enters the value in first text field or edit text to be specific..Is there any method for that..??
Asked
Active
Viewed 401 times
2
-
http://stackoverflow.com/questions/4310525/android-on-edittext-changed-listener See this post, – Gjordis Sep 09 '13 at 10:04
3 Answers
4
you can use TextWatcher for that purpose when you change or add a text this listener is called so on every entered text you get event and can change value of another text or button.
et1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});

anddevmanu
- 1,459
- 14
- 19
-
don't forget to press tick mark to indicate that this is right answer – anddevmanu Sep 10 '13 at 07:34
0
Java is Object oriented language, you need to have in mind to which event you are referring. In case of a button (which you don't want) you are doing something WHEN the button is pressed.
So what are you looking for is the event which related to the EditText you are editing.
What is written by anddevmanu are the events of the EditText. So if you have
//creating Edit text;
EditText youEditText;
//connecting to the xml layout
youEditText = (EditText)findViewById(R.id.yourEditTestID);
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Perform your action when the text is changed
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// Perform your action after the text is changed
}
})
;

Gil Allen
- 1,169
- 14
- 24
0
Try this code
EditText e=new EditText(getApplicationContext());
e.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
//your code.......
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});

ADT
- 255
- 1
- 4
- 14