Android Copy And Paste Multiple Text
I have used android clipboard manager to copy and paste text. Like whatsapp, i would like to copy multiple text from listview and paste those. I am able to do like this, StringBuil
Solution 1:
I guess, you could add multiple ClipData.Item
to your ClipData
. So instead of using static method newPlainText
, create your new ClipData
using
ClipData(ClipDescription description, ClipData.Item item)
or any other constructor available.
I have used getItemCount
method of ClipData
to demonstrate that it is indeed a indexed list of values, so you can definitely use getItemAt
to fetch any ClipData.Item
from any position, provided position is not leading you to OutOfBoundException
. Below code is very novice, but would serve the purpose of demonstration I believe. Let me know if you need any more help.
publicclassMainActivityextendsAppCompatActivity {
ClipboardManager clipboard;
staticintvar=0;
ClipData clipData;
TextView tvClip;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvClip = (TextView) findViewById(R.id.tv_add);
clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ButtonbtnClip= (Button) findViewById(R.id.btn_add);
btnClip.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
ClipData.Itemitem=newClipData.Item("var" + var);
if (clipData == null) {
clipData = newClipData(newClipDescription("your_clip_description", newString[]{ClipDescription.MIMETYPE_TEXT_PLAIN}), item);
clipboard.setPrimaryClip(clipData);
}
clipData.addItem(item);
}
});
ButtonshowClip= (Button) findViewById(R.id.btn_show);
showClip.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
if (clipData != null)
tvClip.setText("count = " + clipData.getItemCount());
}
});
}
}
Post a Comment for "Android Copy And Paste Multiple Text"