1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Kotlinのタップで画面遷移、長押しでクリップボードにコピー

Last updated at Posted at 2021-03-26

###タップでブラウザに画面遷移

click
  view.setOnItemClickListener() { parent, view, position, id ->
       var uri = "https://something"
       var intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
       startActivity(intent)
       true
  }

###長押しでテキストコピー

longClick
   var clipboard: ClipboardManager = applicationContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
   view.setOnItemLongClickListener() { parent, view, position, id ->
       var copyText: String = view.getItemAtPosition(position) as String;
       var clipData = ClipData.newPlainText("コピーしたテキスト", copyText)
       clipboard.setPrimaryClip(clipData)
       var toastText = copyText + " " + "コピーしました"
       Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT).show();
       true
   }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?