Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android paste event

Is there a way to catch the paste event in my application? I must do something when I click long on an editText and select Paste from context menu. Thanks

like image 357
Buda Gavril Avatar asked Feb 02 '23 21:02

Buda Gavril


1 Answers

Create menu.xml with position 'paste'

Register contextMenu to your EditText

EditText et=(EditText)findViewById(R.id.et);
registerForContextMenu(et);

Create contextMenu

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);    
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;  
    menu.setHeaderTitle("title");
}

Create method menu onClick

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();     
    switch (item.getItemId()) {
    case R.id.paste:      
        break;     
    }
    return true;
}
like image 58
zirael Avatar answered Feb 06 '23 14:02

zirael