Reputation: 123
I am using clipboard code like below in my app.Everything is working fine if i copy one item at a time.But when we copy 2-3 items one after other and paste somewhere it starts retrieving repeated past value from clipboard rather than the current value.After googling a lot i came to know that its a problem with Samsung phones and i need to clear clipboard history for that.But i could not find any way to clear clipboard history.
Public void CopyToClipboard {
int pos = (Integer) v.getTag();
StatusEntity obj=getItem(pos);
ClipboardManager clipmanager= (ClipboardManager)getContext().getSystemService(getContext().CLIPBOARD_SERVICE);
ClipData clip=ClipData.newPlainText("data",obj.getStatus());
clipmanager.setPrimaryClip(clip);
Toast.makeText(getContext(), "Copied to clipboard", 1000).show();
}
Hoping that anyone of you can help me regarding this .Any help would be appreciated.
Upvotes: 0
Views: 292
Reputation: 123
I have solved it myself.It was a problem with the tag......i have changed it to value Like below and its working fine now.
package com.gippy.status99;
import java.util.List;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class StatusAdapter extends ArrayAdapter<StatusEntity> {
Context context;String copytext;int id;
public StatusAdapter(Context context, int resource,
int textViewResourceId, List<StatusEntity> objects) {
super(context, resource, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// Only create view if convertView is null
if(convertView == null) {
LayoutInflater inflater=LayoutInflater.from(getContext());
convertView=inflater.inflate(R.layout.status_list_item,parent,false);
}
TextView txtCategory=(TextView)convertView.findViewById(R.id.txt_status);
StatusEntity obj=getItem(position);
txtCategory.setText(obj.getStatus());
Button btn_copy=(Button)convertView.findViewById(R.id.img_btn_copy);
btn_copy.setTag(txtCategory.getText().toString());
btn_copy.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Get the saved value
String item = (String) v.getTag();
ClipboardManager clipmanager= (ClipboardManager)getContext().getSystemService(getContext().CLIPBOARD_SERVICE);
clipmanager.setText("");
Toast.makeText(getContext(), clipmanager.getPrimaryClip().toString(),1000).show();
// ClipData clip=ClipData.newPlainText("data",obj.getStatus());
ClipData clip=ClipData.newPlainText("data",item);
clipmanager.setPrimaryClip(clip);
Toast.makeText(getContext(),item,1000).show();
// Toast.makeText(getContext(), "Copied to clipboard", 1000).show();
}
});
return convertView;
}
}
And it is solved.
Upvotes: 1