By using the below code for EditText you can get the event for Cut/Copy/Paste
And you have to create editText like below.And you can hide the soft keyboard after event fired...
<com.example.textlink.EditTextMonitor
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:hint="EditText" />
Create one java file in your package...
public class EditTextMonitor extends EditText {
private final Context mcontext; // Just the constructors to create a new
// EditText...
public EditTextMonitor(Context context) {
super(context);
this.mcontext = context;
}
public EditTextMonitor(Context context, AttributeSet attrs) {
super(context, attrs);
this.mcontext = context;
}
public EditTextMonitor(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mcontext = context;
}
@Override
public boolean onTextContextMenuItem(int id) {
// Do your thing:
boolean consumed = super.onTextContextMenuItem(id);
// React:
switch (id) {
case android.R.id.cut:
onTextCut();
break;
case android.R.id.paste:
onTextPaste();
break;
case android.R.id.copy:
onTextCopy();
}
return consumed;
}
/**
* Text was cut from this EditText.
*/
public void onTextCut() {
InputMethodManager imm = (InputMethodManager) getContext()
.getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Toast.makeText(mcontext, "Event of Cut!", Toast.LENGTH_SHORT).show();
}
/**
* Text was copied from this EditText.
*/
public void onTextCopy() {
InputMethodManager imm = (InputMethodManager) getContext()
.getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Toast.makeText(mcontext, "Event of Copy!", Toast.LENGTH_SHORT).show();
}
/**
* Text was pasted into the EditText.
*/
public void onTextPaste() {
InputMethodManager imm = (InputMethodManager) getContext()
.getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Toast.makeText(mcontext, "Event of Paste!", Toast.LENGTH_SHORT).show();
}}