I have Dynamic Table. When the user enter quantity then Value (TextView) should update (qty * price).
My problem is that I am creating the TextView & EditText dynamically. How to get the Id of TextView?
EditText txtQty = new EditText(this);
txtQty.setId(i);
txtQty.setVisibility(1);
txtQty.setHint("0.00");
txtQty.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
tr.addView(txtQty);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(txtQty, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(txtQty.getWindowToken(), 0);
txtQty.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.v("TAG", "afterTextChanged" + s.toString());
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
Log.v("TAG", "beforeTextChanged");
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.v("TAG", "onTextChanged");
}
});
TextView txtVal = new TextView(this);
txtVal.setTextSize(1, 12);
createView(tr, txtVal,"0.00");
Inside the afterTextChanged() method I want to set the value(txtVal), for example txtVal .setText(215847.00);
How can we call txtVal inside the afterTextChanged() method?
Try declaring your
txtValbefore youaddTextChangedListener(). You probalby need to declaretxtValasfinal TextView txtVal. Then you should be able to set the text oftxtVal.