onKey method of OnKeyListener is not calling

Put your problem here if it does not fit any of the other categories.

onKey method of OnKeyListener is not calling

Postby srinuv28 » Wed Dec 02, 2009 8:43 am

Hi..

Please help on this it's urgent..


When I press key from softkeypad onKey method is not calling, when I press back button at that time only it is calling, and when I press numbers at that time also onKey method is calling.

onKey mothod of OnKeyListener is calling when I am typing with Virtual keyboard .

I am posting my sample code please anyone help on this...

*******************************************************************************************
package com.demo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.TextView;

public class TextFiledDemo extends Activity {

private TextView textView;
private EditText messageBox;
private String className = this.getClass().getSimpleName();


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


textView = (TextView) findViewById(R.id.textView);
messageBox = (EditText) findViewById(R.id.msgBox);
// messageBox.set

//messageBox.setOnKeyListener(onKeyListener);



messageBox.setOnKeyListener(new OnKeyListener() {


@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {

String methodName = "onKey";
String message = messageBox.getText().toString().trim();
textView.setText(message);
Log.d(className, methodName + " message[" + message + ".]");
return false;
}
});

}

//on
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/layout"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView android:id="@+id/textView" android:layout_width="245px"
android:layout_height="wrap_content" android:singleLine="true" android:text="TextView"
android:gravity="left" android:layout_x="37px" android:layout_y="51px">
</TextView>
<EditText android:id="@+id/msgBox" android:layout_width="303px"
android:layout_height="wrap_content" android:singleLine="true"
android:textSize="18sp" android:layout_x="7px" android:layout_y="374px" android:inputType="none">
</EditText>

</AbsoluteLayout>


*******************************************************************************************

Thanks
Srinu
Last edited by srinuv28 on Thu Dec 03, 2009 6:45 am, edited 1 time in total.
srinuv28
Developer
Developer
 
Posts: 36
Joined: Wed Nov 04, 2009 4:04 am

Top

Postby srinuv28 » Thu Dec 03, 2009 3:20 am

Hi..

Anyone help on this.. it's urgent..

Thanks
Srinu
srinuv28
Developer
Developer
 
Posts: 36
Joined: Wed Nov 04, 2009 4:04 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests