Java first selected text value geting on second selection from clipboard
===

I tried to get selected text using the java code.But the first selected value only getting on second selection.I tried to clear first selected value by clearing clipboard but on second selection it is returning empty string... please help


code

     import android.app.Activity;
     import android.os.Bundle;
     import android.text.ClipboardManager;
     import android.util.Log;
     import android.view.KeyEvent;
     import android.view.Menu;
     import android.view.MenuItem;
     import android.view.View;
     import android.view.View.OnClickListener;
     import android.webkit.WebView;
     import android.widget.Button;
     import android.widget.EditText;
     import android.widget.Toast;
 
     import com.test.R;
 
     public class WebviewcopyActivity extends Activity implements OnClickListener {
      /** Called when the activity is first created. */
      private WebView testWebview;
      private EditText editText;
      private ClipboardManager clipboard;
      private Button copyButton;
      private Button pasteButton;
      String s=new String();
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       testWebview = (WebView) findViewById(R.id.webView1);
       s="";
       clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
       copyButton = (Button) findViewById(R.id.copy);
       pasteButton = (Button) findViewById(R.id.paste);
       copyButton.setOnClickListener(this);
       pasteButton.setOnClickListener(this);
       editText = (EditText) findViewById(R.id.editText1);
       testWebview.loadUrl("file:///android_asset/about.html");
       emulateShiftHeld(testWebview);
 
       // editText.setText(s);
 
      }
 
      private void emulateShiftHeld(WebView view) {
       try {
       KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
       KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
       shiftPressEvent.dispatch(view);
       registerForContextMenu(view);
       //Toast.makeText(this, "select_text_now", Toast.LENGTH_SHORT).show();
 
       } catch (Exception e) {
       Log.e("dd", "Exception in emulateShiftHeld()", e);
      }
      }
 
     public void onClick(View v) {
     switch (v.getId()) {
     case R.id.copy:
      emulateShiftHeld(testWebview);
      break;
     case R.id.paste:
     //editText.setText("");
      s=clipboard.getText().toString();
      editText.setText(s);
       Toast.makeText(this, clipboard.getText(), Toast.LENGTH_SHORT)
        .show();
      //clipboard.eetText();
   
      break;
 
     }
    }
 
    }



