Android chat room copy/delete text

// long press click
public boolean onItemLongClick(AdapterView arg0, View arg1,
     final int pos, long id) {

                // AlertDialog can try to move to global variable, can avoid to multiple creating.
                AlertDialog.Builder dialog = new AlertDialog.Builder(ChatActivity.this);
                String strCopy = getResources().getString(R.string.copy);
                final String strDel = getResources().getString(R.string.delete);
                String[] options = { strCopy, strDel };  // copy and delete items
                DialogInterface.OnClickListener actionListener = new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      switch (which) {
                      case 0: // Copy
                       String copyTxt = _list.get( pos ).getText();
                       //place your TextView's text in clipboard
                       ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
                      case 1: // Delete
                       AlertDialog.Builder delete = new AlertDialog.Builder(ChatRoomActivity.this);
                       delete.setTitle( strDel );
                          // if confirm to del item, remove it from list and update adapter
                       delete.setPositiveButton( R.string.confirm,  new DialogInterface.OnClickListener() {  
                              public void onClick(DialogInterface dialog, int whichButton) {  
                               _list.remove( pos );
                       delete.setNeutralButton( R.string.cancel, null );
                       Toast.makeText( ChatActivity.this, "undefine this type in ChatActivity", Toast.LENGTH_LONG ).show();
                dialog.setItems(options, actionListener);
                // end AlertDialog create

       return true;


Popular posts from this blog

tex2D vs. tex2Dproj

Fast subsurface scattering

Physically-Based Rendering in WebGL