You do not instantiate this class directly; instead, retrieve it through getSystemService(String).

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
<TextView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/hello"
 />
<EditText
 android:id="@+id/src"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
<TextView
 android:id="@+id/dest"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
<Button
 android:id="@+id/copynpaste"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Copy'n Paste"
 />
</LinearLayout>
AndroidCopynPaste.java
package com.exercise.AndroidCopynPaste;
import android.app.Activity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AndroidCopynPaste extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
  
     final EditText src = (EditText)findViewById(R.id.src);
     final TextView dest = (TextView)findViewById(R.id.dest);
     Button copynPaste = (Button)findViewById(R.id.copynpaste);
  
     final ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
  
     copynPaste.setOnClickListener(new Button.OnClickListener(){
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    clipBoard.setText(src.getText());
    dest.setText(clipBoard.getText());
    
   }});
 }
}
2 comments:
hi could you check the download link please ? thank you !!!
I want to copy smiley stored in my drawable resource folder. Please provide me an example of how to do that.
Post a Comment