Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old February 7th, 2012, 01:19 AM   #1 (permalink)
New Member
 
Join Date: Feb 2012
Posts: 14
 
Device(s):
Thanks: 0
Thanked 1 Time in 1 Post
Default Am I developing this properly?

Right now I have an Android application I made and it has a list of items I can select. The list of items is displayed from an array of Strings and I use a case switch to check which one was clicked. This is very bad because it's a case switch which checks the ID of the clicked item and there are 180 items. So if you add another item somewhere in the middle, you have to manually change the subsequent case switch ID to be increased by one. Know what I mean? Is there a better way to find out which one has been pressed so an action can be associated to it?

Also on the same application, clicking a menu item displays information about that item including a photo and some text details. Every detail page is the same except for the content but right now I have a separate .java file for each page and also a separate .xml file for the layout of each page. Each .java file calls its own .xml file and each .xml file calls its own photo image and String for the details. So this means I have 180 .java files, 180 .xml files and 180 .png images.

Is there a better way to dynamically create these so I don't have so many files? Thanks everyone.

Deemar is offline  
Reply With Quote
Sponsors
Old February 7th, 2012, 07:00 PM   #2 (permalink)
Junior Member
 
jonathanrz's Avatar
 
Join Date: Jan 2012
Location: Brazil - Blumenau, SC
Posts: 69
 
Device(s): Motorola Defy - Gingerbread(2.3.3)
Thanks: 12
Thanked 5 Times in 4 Posts
Send a message via MSN to jonathanrz jonathanrafaelz
Default

Quote:
Originally Posted by Deemar View Post
Right now I have an Android application I made and it has a list of items I can select. The list of items is displayed from an array of Strings and I use a case switch to check which one was clicked. This is very bad because it's a case switch which checks the ID of the clicked item and there are 180 items. So if you add another item somewhere in the middle, you have to manually change the subsequent case switch ID to be increased by one. Know what I mean? Is there a better way to find out which one has been pressed so an action can be associated to it?
Do you need to do a different treatment of each item?

What you have to do when the user clicks in a item?
jonathanrz is offline  
Reply With Quote
Old February 7th, 2012, 07:19 PM   #3 (permalink)
New Member
 
Join Date: Feb 2012
Posts: 14
 
Device(s):
Thanks: 0
Thanked 1 Time in 1 Post
Default

Nope. When the user clicks an item it displays the informational page for that item which always has the same layout with different content. It displays a picture at the top and text underneath.

The picture is different for each item as well as the text. Page layout is the same. Think about an office directory that would show a list of names and when you click one, it shows the employee's picture as well as some information about them.
Deemar is offline  
Reply With Quote
Old February 8th, 2012, 02:44 AM   #4 (permalink)
Junior Member
 
jonathanrz's Avatar
 
Join Date: Jan 2012
Location: Brazil - Blumenau, SC
Posts: 69
 
Device(s): Motorola Defy - Gingerbread(2.3.3)
Thanks: 12
Thanked 5 Times in 4 Posts
Send a message via MSN to jonathanrz jonathanrafaelz
Default

You can set the images and other information in a map where the key is the id of the image, in the OnClick, you just have to take the information on the map.
jonathanrz is offline  
Reply With Quote
Old March 6th, 2012, 02:26 AM   #5 (permalink)
New Member
 
Join Date: Feb 2012
Posts: 14
 
Device(s):
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by jonathanrz View Post
You can set the images and other information in a map where the key is the id of the image, in the OnClick, you just have to take the information on the map.
Could you please tell me what you mean by this? I tried loading the class for the selected item but I can only get the position of the item in the list or the ID.....which is basically the position in a zero based array. I am having a lot of trouble trying to figure out how to load a class based on the selected item without having to explicitly specify the class name for each possible case.
Deemar is offline  
Reply With Quote
Old March 6th, 2012, 03:25 AM   #6 (permalink)
Junior Member
 
jonathanrz's Avatar
 
Join Date: Jan 2012
Location: Brazil - Blumenau, SC
Posts: 69
 
Device(s): Motorola Defy - Gingerbread(2.3.3)
Thanks: 12
Thanked 5 Times in 4 Posts
Send a message via MSN to jonathanrz jonathanrafaelz
Default

Here is the hash map documentation: HashMap | Android Developers

In your hash map, your id will be the key and the class name, the value.
jonathanrz is offline  
Reply With Quote
Old March 8th, 2012, 03:06 AM   #7 (permalink)
New Member
 
Join Date: Feb 2012
Posts: 14
 
Device(s):
Thanks: 0
Thanked 1 Time in 1 Post
Default

It just looks like a 2 dimensional array, is that all it is?
Deemar is offline  
Reply With Quote
Old March 8th, 2012, 03:48 AM   #8 (permalink)
Junior Member
 
jonathanrz's Avatar
 
Join Date: Jan 2012
Location: Brazil - Blumenau, SC
Posts: 69
 
Device(s): Motorola Defy - Gingerbread(2.3.3)
Thanks: 12
Thanked 5 Times in 4 Posts
Send a message via MSN to jonathanrz jonathanrafaelz
Default

Yes and no.

I suggest you study hashmaps.
jonathanrz is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:15 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo