使用kotlin在android studio中共享意图文本 [英] share intent text in android studio using kotlin

查看:111
本文介绍了使用kotlin在android studio中共享意图文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Kotlin的共享意图在 CardView 中共享文本,但是kotlin的代码最后一行存在问题 代码

I want to share text in my CardView using share Intent using kotlin but there is a problem with last line in the code in kotlin the code

 val shareIntent = Intent()
            shareIntent.action = Intent.ACTION_SEND
            shareIntent.putExtra(Intent.EXTRA_STREAM, "ali")
            shareIntent.type = "text/plain"
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)))

这是代码中的问题

startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)))

请帮助我

查看图片以了解我

图片

https://ibb.co/jQwYXw

https://ibb.co/id0tXw

https://ibb.co/fbCU5G

适配器完整代码

class MyAdapter(context: Context, listItem: ArrayList<com.EliteTeam.comedytaste.Model.Movie>) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() {

var Context = context
var movieList = listItem;
var layoutInflator = LayoutInflater.from(context)

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder {

    var inflateView = layoutInflator.inflate(R.layout.single_item, parent, false)

    return MyViewHolder(inflateView)
}

override fun onBindViewHolder(holder: MyViewHolder?, position: Int) {

    holder?.moviewTitle?.text = movieList[position].name
    holder?.movieDescription!!.text=   movieList[position].description
    //holder!!.cardImageView!!.background=   movieList[position].image

    holder?.onclick(Context, position)
    holder!!.cardImageView.setBackgroundResource(movieList[position].image)
}

override fun getItemCount(): Int {

    return movieList.size
}

class MyViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

    var moviewTitle: TextView = itemView?.findViewById(R.id.movieTitleTextView)!!
    var movieDescription: TextView = itemView!!.findViewById(R.id.movieDescriptionTextView)
    var cardImageView: CardView = itemView!!.findViewById(R.id.imageCard)
    var share: ImageButton = itemView!!.findViewById(R.id.share)

    fun onclick(context: Context, position: Int) {
        cardImageView.setOnClickListener {

    }

       share.setOnClickListener {

           val shareIntent = Intent()
         shareIntent.action = Intent.ACTION_SEND
           shareIntent.putExtra(Intent.EXTRA_TEXT, "ali")
          shareIntent.type = "text/plain"


           startActivity(Intent.createChooser(shareIntent,"send to"))

}} }}

推荐答案

尝试一下:- 仅在必须发送图像之类的二进制数据时使用 Intent.EXTRA_STREAM ,如果要发送文本,请使用 Intent.EXTRA_TEXT

Try this :- Use Intent.EXTRA_STREAM only when you have to send Binary data like images , if you want to sent text use Intent.EXTRA_TEXT

    val shareIntent = Intent()
    shareIntent.action = Intent.ACTION_SEND
    shareIntent.type="text/plain"
    shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
    startActivity(Intent.createChooser(shareIntent,getString(R.string.send_to)))

这篇关于使用kotlin在android studio中共享意图文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆