Copy text from listview to clipboard on long press
<p>I am making an app that will copy the text on list view after long press. I created an array of string in the listview now I want to implement long press event in fragment. Like when I long press the list Item 1 it should be copied in to the clipboard. How can I implement it?</p>

<p><strong>OneFragment.java</strong></p>

<pre><code>import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dragedy.kickasshumor.R;


public class OneFragment extends Fragment{

    public OneFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_one, container, false);
    }

}
</code></pre>

<p><strong>FragmentOne.xml</strong></p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    &lt;ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/list"
        android:id="@+id/listView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p><strong>Strings.xml</strong></p>

<pre><code>&lt;resources&gt;
   &lt;string-array name="list"&gt;
        &lt;item&gt;Item 1&lt;/item&gt;
        &lt;item&gt;Item 2&lt;/item&gt;
        &lt;item&gt;Item 3&lt;/item&gt;
        &lt;item&gt;Item 4&lt;/item&gt;
        &lt;item&gt;Item 5&lt;/item&gt;
        &lt;item&gt;Item 5&lt;/item&gt;
        &lt;item&gt;Item 5&lt;/item&gt;
        &lt;item&gt;Item 5&lt;/item&gt;
        &lt;item&gt;Item 5&lt;/item&gt;
    &lt;/string-array&gt;

&lt;/resources&gt;
</code></pre>