• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Am I developing this properly?

Deemar

Newbie
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.
 
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?
 
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.
 
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.
 
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.
 
Back
Top Bottom