I am a new about making app. I want to pass the data from adapter to new activity with intent. I want to transfer PastNotesActivity, but it does not working.Because oldTitleName shows me the error: found String, Required editable. How can ı fix it ?
class NoteAdapter(private var titleText: ArrayList<String>, private var image: ArrayList<String>) : RecyclerView.Adapter<NoteAdapter.ViewHolder>() {
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val itemTitle : TextView = itemView.findViewById(R.id.recyclerTitleText)
val itemImage : ImageView = itemView.findViewById(R.id.recyclerImage)
init {
itemView.setOnClickListener { v: View ->
// Toast.makeText(itemView.context,"You clicked on item # ${position + 1}", Toast.LENGTH_SHORT).show()
val intent = Intent(itemView.context, PastNotesActivity::class.java)
intent.putExtra("oldTitle", titleText[position])
itemView.context.startActivity(intent)
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.recycler_row, parent, false)
return ViewHolder(v)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.itemTitle.text = titleText[position]
Picasso.get().load(image[position]).into(holder.itemImage)
}
override fun getItemCount(): Int {
return titleText.size
}
}
This is PastNotesActivity, oldTitleName shows me the error: found String, Required editable. How can ı fix it ?
class PastNotesActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_past_notes)
val intent = intent
val oldTitleName = intent.getStringExtra("oldTitle")
pastTitleText.text = oldTitleName
val navBarTitle = intent.getStringExtra("oldTitle")
supportActionBar?.title = navBarTitle
}
}
Lets say that you are passing the text of an item from your recyclerView to the textView of a desired activity.
Code this...
val intent = Intent(itemView.context, PastNotesActivity::class.java)
intent.putExtra("sampledText", "test123")
And code this in your desired activity...
val textFromIntent = intent.getStringExtra("sampledText")
textView.text = textFromintent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.