• Post Reply Bookmark Topic Watch Topic
  • New Topic

Shopping cart help - Android Studio  RSS feed

 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I hope I've put it in the right place.  Apologies, if I haven't.

I hope this will make sense, too.
What would be the best way to incorporate a file writer in my code for a simple shopping list?

Basically, I am trying to do a shopping cart. You can log in successfully, you can browse through the products (list) and what I'd like to be able to do is click on the item and have it add to a 'cart'. Once products are added to a cart, I'd like to be able to view the cart and hopefully email the list. (this is where the file writer comes in)

Trouble is, I don't actually understand 100% how to do it, and I'd like to do it right. I've been on this for a few months now because I'm beginning and didn't want to ask for help.... but now I am about to give up. But I'd like to learn!

If anyone had any tutorials that I could follow or just reference, that'd be great. I am a beginner but I'd really like to get over this hump.

The goal is to make it simple, (apparently) that's why the use of file writer vs database.

thanks!
Prissy
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Android supports java io package.  So you can always use that.  And as you know to create a file it needs a path.  In android you cant typically two different locations using getExternalStorageDirectory(), it will refer to either sd card or phone internal storage, or you can use getFilesDir(), this path is specific to your app and is not externally available and if the app is uninstalled this will also be deleted.
 
Tim Moores
Saloon Keeper
Posts: 3967
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you considering just files and the built-in DB? For something as temporal as shopping cart, I think I'd go for preferences (less overhead than files, much less overhead than the built-in DB).

What is the connection between a FileWriter and emailing the shopping list? The usual way of emailing something with user interaction would be to use an Intent.

Or is this just an exercise where you're supposed to use a FileWriter no matter whether it makes sense?
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's true.  DB is always better, but it appears be a school/assignment and probably use of filewriter has been asked.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies!

Correct! it's a project. The teacher said to use a file writer to make it simple. But hasn't given us any information on how to use it or even have the "shopping list" saved as a text file and then emailed. I have set the email part up... well if you click on it, it opens the email app etc.

I asked about using the DB, but unfortunately that's not the project.

I've asked how to do it, and "you'll have to google it, or ask SO for help"... SO is a no go zone, they're mean lol.

googling isn't teaching me what I have to do! :/ I've checked the text books and resources given a thousand times, it's not in there and I'm stuck!
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, I have a listview that has items in it. When the user taps the items, it needs to generate a list of all the products that have been tapped.

Noooooooooooo idea!
 
Tim Moores
Saloon Keeper
Posts: 3967
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ListView has a facility to detect when the user clicks on an item, and it can tell you which item that is - have you discovered this facility yet? If not, start with a tutorial on ListView, either from developer.android.com or from vogella.de.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kinda? I'll definitely read that, though. Thank you!

When you click on the items in the list view, it does send the item price to a TextView - that much I've got. It's now viewing the cart and being able to generate a list that I have issues with!

but thank you!
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far as what I understood , your requirement is user selects items from the list.  Selected items are saved in a text file (as per your requirement), and this text file is send as an email attachment.  Is this your requirement?
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! That's it! The requirement was to generate the shopping list we made (or the user selected) and then we have to do something with the list. So I figured email may work easier than texting!
Sorry for the delay in reply!
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what have you done on this so far?
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you log in, you see the list of items and then when you click on them a shopping cart total adds up in a textview... I don't know how to do view the cart or generated list.

Does that make sense?
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have already collected the data on list selection
  You can now have a button click that stores the data in text file and sends as email attachment.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I'm so 'dumb' with this. I think this course is way over my head.

But yes, ideally, I'll like to be able to click a 'cart' button and view what has been selected as well.. is that hard? (for an absolute beginner that is :/)

 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have already done half of that. i.e dispalying the selected item in text view.  I guess your next step should be to save it in a file and before you send this file as email, you can display the file to the user.  I hope this helps.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my understanding an ideal design can be, you should have 2 list views.  One displays the items to be added to cart and the other displays the added items.  From the 2nd list user can remove items.  Apart from these 2 list views you should have a button that creats the file and sends mail.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I've been trying to do since 9 am :/  it's 1:10pm now and I'm getting no where.

thank you so much for replying!
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:As per my understanding an ideal design can be, you should have 2 list views.  One displays the items to be added to cart and the other displays the added items.  From the 2nd list user can remove items.  Apart from these 2 list views you should have a button that creats the file and sends mail.


ahhh yep yep!
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And let us know if you need any further help on this.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I do. I'm not sure which filewriter code to use. We did one assignment in Eclipse with it, but that was with our own text... nothing like this. Apparently I don't need a separate cart to display, just the list and "do something" with the list.

I a) don't know how to get the filewriter code to talk to the listview (and what's been clicked)... and b) where do I even put it in my code?

We get told what to do, with no explanations on how to do it - as if it's come naturally. I used the code from the eclipse project and tried to djust a few things and it's made no file (which i honestly didn't expect it to, little things I'm missing)
So I've deleted it all (not the whole code) and now just staring blankly at the screen lol

I understand what I have to do, I just can't do it.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to one of my initial posts gerFillesDir and getExternal methods.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do I find that?
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These methods falls under android apis itself.  I am giving a small example.



just make sure you have added write to storage permission in manifest.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I'll try and give it a go
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gah!

I have no idea where to put it or what the code should be. I'm just looking in our text book and it's not working for me :/
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you [on the click of a listview item] put listview items into String array first?

If I do that, could I possibly be able to put the items in the array (the ones that have been clicked on in the listview) into the text file?
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are already displaying the selected item in a text view, right?  The same selected item will be added to array/arraylist.
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi yes.. I actually have the string array set up now. Just working on (trying to) make it so it prints to a file.

It displays as a toast message for the moment... but I'm working on changing that. just don't know how just yet
 
Prissy Marie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done a few different filewriter/reader codes - i have no errors but I also don't see the actual file it's apparently printing to. How do I use what has been clicked on to generate a shopping list? When you click on an item, it displays the items in a toast message... but i'm not sure how to generate the list for the user to see what they've clicked/added to cart.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!