我试图将 onClickListener 添加到 RecyclerView 内的按钮,该按钮将复制一个字符串,但它说 getSystemService(CLIPBOARD_SERVICE) 不可用。
public void onBindViewHolder(ViewHolder holder, int position) {
holder.title.setText(cardItems.get(position).title);
holder.content.setText(cardItems.get(position).content);
holder.copyButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
String text;
text = EditText.getText().toString();
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getApplicationContext(), "Text Copied", Toast.LENGTH_SHORT).show();
}
});
}