I am developing one android app in which I have use this code - Link Here
Code Works Well using support-library's Fragment: android.support.v4.app.Fragment
I have placed One button in third_frag.xml
with button id buttonfg3
Now when user click on that button text on that fragment should be get copied
I have modified ThirdFragment
public class ThirdFragment extends Fragment {
Button b1;
TextView ed1;
private ClipboardManager myClipboard;
private ClipData myClip;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ed1=(TextView) container.findViewById(R.id.tvFragThird);
b1 = (Button) container.findViewById(R.id.buttonfg3);
myClipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text;
text = ed1.getText().toString();
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getActivity().getApplicationContext(), "Text Copied", Toast.LENGTH_SHORT).show();
}
});
View v = inflater.inflate(R.layout.first_frag, container, false);
TextView tv = (TextView) v.findViewById(R.id.tvFragFirst);
tv.setText(getArguments().getString("msg"));
return v;
}
public static FirstFragment newInstance(String text) {
FirstFragment f = new FirstFragment();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
}
but when i place setOnClickListener code ,Application stops working..