2014-02-11 71 views
0

我遇到了onKey問題。我已經編寫了一些EditText,我想在按下Enter鍵時關注下一個EditText,我知道這麼做,但是當我按下後,只會調用onKey,有人可以幫助我嗎?感謝EditText中的onKey以編程方式構建Android

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

回答

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

問題是不是如果的問題是,安其方法,只有被稱爲如果我按回 – javisilox

相關問題