Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking the selecting text in android webview

Tags:

android

In android webview we can able to select the text in web pages. After selection finished , the toast will appear like "text copied to clipboard". Whether its possible to avoid that toast? Also i want to call a function after selecting text. how can i do this?

help me...

like image 732
Prasanth Avatar asked Dec 14 '11 10:12

Prasanth


1 Answers

public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == android.view.MotionEvent.ACTION_UP) {              
        // when user finished selection this loop will execute to get 
        // selected text in webview.
        if(mark_text == true)
        {                       
             mark_text = false;
             clipboardManager.setText("XXXXXX");    
             webView.postDelayed(onClipBoard, 1000);
        }
    }
 }


private Runnable onClipBoard=new Runnable() {
   public void run() {                  
            // if selected text is copied in clipboard toast will show the  
            // correct text otherwise else part will execute                
      if (!clipboardManager.getText().toString().equalsIgnoreCase("XXXXXX")) {
            Toast.makeText(getApplicationContext(),
                    "selected Text = " + clipboardManager.getText().toString(),
                    Toast.LENGTH_LONG).show();
            clipboardManager.setText("XXXXXX");

      } else {
           webView.postDelayed(onClipBoard, 1000);
      }     
   }
};
like image 114
Prasanth Avatar answered Oct 06 '22 01:10

Prasanth