EditText: show input window, retrieve text, and change its height
In my project, I have a list of products available in table-layout. I need two things
- When the开发者_开发问答 user click on
EditText
numeric keypad should display below it. - After user enter numeric value, how we can get the entered Edited text box value.?
I have EditText
like this:
EditText txtQty = new EditText(this);
txtQty.setTextSize(2, 12);
txtQty.setHeight(4);
txtQty.setWidth(6);
txtQty.setId(i);
txtQty.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
txtQty.setText("0.00");
tr.addView(txtQty);
- How we can reduce
EditText
box height? I did but it didn't change that much
Please give me idea...
Thanks in advance
You could use 2 events to acheive this. First is onTextChangedListener if you want to get text from EditText each time it is edited. Second is onKeyDownListener. You can check whether the key equals to enter. getText().toString() is used to get the text of EditText. Here is a code snippet:
myEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
String tmp = draw.myEditText.getText().toString().trim();
//to hide keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
}
return false;
}
});
精彩评论