EditText中的onKey以编程方式构建Android

时间:2014-02-11 15:48:50

标签: android android-edittext

我的onKey有问题。我以编程方式构建了一些EditText,我想在按下回车时关注下一个EditText,我知道这样做,但是当我按回来时onKey就被调用了,有人可以帮我吗?感谢

        layout = (LinearLayout)findViewById(R.id.listajugadores);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(0, 10, 0, 0);
        et_jugadores = new ArrayList<EditText>();
        bundle = getIntent().getExtras();


        for (int i = 0; i < bundle.getInt("num_jugadores"); i++) {
            EditText et_aux = new EditText(this);
            et_aux.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
            et_aux.setHint(getString(R.string.jugador) +" " + String.valueOf(i+1));
            et_aux.setBackgroundResource(R.drawable.sh_edit_text);
            et_aux.addTextChangedListener(textwatcher);
            et_aux.setOnKeyListener(new OnKeyListener() {

                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    Log.d("KEY","aaaaa");
                    return false;
                }
            });
            et_jugadores.add(et_aux);
            layout.addView(et_aux,layoutParams);                
        }

1 个答案:

答案 0 :(得分:0)

如果

,请使用此功能
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction()==KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                //do something here
                return true;
            }
            return false;
        }