How to create a dynamic table with borders in android
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(Contex开发者_如何转开发t.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 txtVal
before you addTextChangedListener()
. You probalby need to declare txtVal
as final TextView txtVal
. Then you should be able to set the text of txtVal
.
精彩评论