I have an extended edittext, as follows:
test.class
public class test extends EditText {
public test (Context context, AttributeSet attrs)
{
super (context, attrs);
}
@ Override
public boolean onKeyPreIme (int keyCode, KeyEvent event)
{
if (event.getKeyCode () == android.view.KeyEvent.KEYCODE_BACK) {
/ / To do something
}
return super.onKeyPreIme (keyCode, event);
}
}
OnKeyPreIme which used to precede the soft keyboard input back to capture the key, then use the following procedure:
touchpad.class
private test editText1;
@ Override
public void onCreate (Bundle savedInstanceState) {
editText1 = (test) findViewById (R.id.editText1);
}
public void back_pressed () {
/ / Some code
}
Now I want to know is how to click the back button this action from test.class onKeyPreIme () reached touchpad.class and trigger back_pressed (), thank you!
Reply:
upupup .........
Reply:
You wear a touchpad this activity you edittext, call its methods, or pass a handle to textview, to handle calls through
Reply:
Reply:
Can elaborate on that? Thank you!
Reply:
Intent intent = new Intent ();
intent.setAction ("w.w.xxxx");
intent.putExtra ("data", 5555);
sendBroadcast (intent);
/ / -------------------
public class DataReceiver extends BroadcastReceiver {
@ Override
public void onReceive (Context context, Intent intent) {
/ / TODO Auto-generated method stub
double data = intent.getDoubleExtra ("data", 0);
tv.setText ("data is:" + data);
}
}
Reply:
View.OnClickListener
Reply:
You can also use SharedPreferences
Reply:
test
public class test extends EditText {
public test (Context context, AttributeSet attrs) {
super (context, attrs);
}
OnKeyBackPressed keybackpressed = null;
public void SetOnKeybackPressed (OnKeyBackPressed k) {
keybackpressed = k;
}
@ Override
public boolean onKeyPreIme (int keyCode, KeyEvent event) {
if (event.getKeyCode () == android.view.KeyEvent.KEYCODE_BACK) {
/ / To do something
if (keybackpressed! = null)
keybackpressed.back_pressed ();
}
return super.onKeyPreIme (keyCode, event);
}
public static interface OnKeyBackPressed {
public void back_pressed ();
}
}
touchpad
editText1.SetOnKeybackPressed (new OnKeyBackPressed () {
@ Override
public void back_pressed () {
/ / ToDo something
}
});
No comments:
Post a Comment