final EditText edtxt = (EditText)findViewById(R.id.startPage_editText);
edtxt.setOnEditorActionListener(new OnEditorActionListener() {
	@Override
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
			Log.i(getClass().getSimpleName(), "Enter was pressed");
		    	Intent intent= new Intent(getApplicationContext(),TabAntwortenAnzeigenActivity.class);
		    	String in = edtxt.getEditableText().toString();
		    	Log.i(getClass().getSimpleName(), "Strin = "+in);
		    	intent.putExtra("search", in);
		    	startActivity(intent);
		    	return true;
		}
		return false;
	}
});
Trackback

2 comments until now

  1. Christian

    Hallo,

    wenn man den den Code verwendet um z.B. ne simple Ausgabe auf die Standardausgabe zu machen wird der Code doppelt ausgeführt. z.b. bei

    text1.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

    System.out.println(“Test”);

    return true;
    }
    return false;
    }
    });

    kommt:

    Test
    Test

    heraus.

    fiel mir gerade so auf.

  2. Hallo,

    @Christian

    Das Event wird bei Key down und Key up ausgeführt.
    Also einfach noch event.getAction() == KeyEvent.ACTION_DOWN mit in die if reinnehmen.

Add your comment now