开发者

EditText: show input window, retrieve text, and change its height

开发者 https://www.devze.com 2023-04-01 07:40 出处:网络
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.

In my project, I have a list of products available in table-layout. I need two things

  1. When the开发者_开发问答 user click on EditText numeric keypad should display below it.
  2. 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); 
  1. How we can reduce EditText box height? I did but it didn't change that much

EditText: show input window, retrieve text, and change its height

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;
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号