Code example for ClipboardManager

Methods: getText, hasText

0
  private final Button.OnClickListener clipboardListener = new Button.OnClickListener() {
    @Override 
    public void onClick(View v) { 
      ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
      // Should always be true, because we grey out the clipboard button in onResume() if it's empty 
      if (clipboard.hasText()) { 
        launchSearch(clipboard.getText().toString()); 
      } 
    } 
  }; 
 
  //纯文本 
  private final View.OnKeyListener textListener = new View.OnKeyListener() {
    @Override 
    public boolean onKey(View view, int keyCode, KeyEvent event) { 
      if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { 
        String text = ((TextView) view).getText().toString(); 
        if (text != null && text.length() > 0) { 
          launchSearch(text); 
        } 
        return true;