Reputation: 11
I have recently created a class that has a text view and an edit text. I am using the edit text in order to get some input from an user, and I would like for my text view to display what the user types in. I need to mention that my labels are created dynamically and I am not sure how to reference them. C0uld you give me a clue?
public TextView itemName(Context context){
final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final TextView itemName = new EditText(context);
itemName.setLayoutParams(lparams);
return itemName;
}
public EditText desiredQuantity(Context context) {
final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final EditText desiredQuantity = new EditText(context);
desiredQuantity.setLayoutParams(lparams);
desiredQuantity.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
itemName.setText(desiredQuantity.getText().toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
return desiredQuantity;
}
Upvotes: 0
Views: 65
Reputation: 6919
onTextChanged
called when user change the text from edittext.
et1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
t1.setText(et1.getText().toString());
}
});
Upvotes: 1