0

So I'm developer and currently working on an android to-do list app.

I'm looking for a way to store the date entered by the user:

  • time
  • title
  • description
  • etc..

Is there is a way to create variables dynamically ? (e.g. task1, task2, etc..)

Or should I work with 3 arrays for the time, title, description.

For example:

Time = ["5pm","4:15pm","6:30am"]
Title = ["Pick up the kids","meet Ammy"]

Thank you.

1
  • 1
    You should create a custom class like Task. As you don't know howmany tasks there will be, you will not use an array but a List such as ArrayList Commented Mar 22, 2018 at 13:41

1 Answer 1

2

How about creating a class Task and keep them in a list?

data class Task(val title: String, val time: String)

val tasks = listOf(Task(“Meet Amy”, “5pm”), Task(“Pick up kids”, “3pm”)
Sign up to request clarification or add additional context in comments.

4 Comments

Am I obliged to use Val? because the user may want to make some changes. And thank you so much.
Ofcourse not. You can use var or val whatever suits your requirements. It would be a good idea indeed to have the Task class properties as var as the user may naturally make changes to the tasks
I am sorry for coming back, I've seen a lot of people using arraylists for the same purpose. For example storing people names and ages and then print them out aside. (In my case Title and time). Even the guys who commented on my question suggested to use an arraylist. My question is, can you please make it clearer for me on how to use this method? Thanks for helping.
@funris it is better that you ask a new question with the exact problem that you’re having.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.