views:

39

answers:

1

Hi, i'm developing an android app, and what i have is a String array of restaurants in one class...

static final String[] AtoZ = new String[] {

    "Ananda",
    "Brambles Cafe", "Brannigans", "Buona Sera",
    "Cafe Mao", "Cafe Mimo",
    "Dante",
    "Eddie Rockets",
    "Frango's World Cuisine",
    "Nando's",
    "Overends Restaurant @ Airfield House",
    "Pizza Hut",
    "Roly Saul",
    "Siam Thai","Smokey Joes","Sohag Tandoori",
    "TGI Friday","The Rockfield Lounge", "Winters Bar",
    "Al Boschetto","Baan Thai", "Bella Cuba", "Bellamys","Bianconis","Canal Bank Cafe",
    "Canalettos Restaurant","Chandni Restaurant", "Chill Out Cafe", "Crowes", "Da Vincenzo", "Druids", "Dylan",
    "Epic Restaurant", "Jewel in the Crown", "Juniors", "Kanum Thai","Kites", "Koishi","Maia Restaurant",
    "Mangetu Restaurant", "Millers Pizza Kitchens",
    "O'Connells Restaurant", "Ocras Restaurant", "Orchid Szechuan Restaurant", "Roly's Bistro",
    "Ryans Beggars Bush", };

i have created a view for each of these restaurants aswell in my layouts folder.

so this array is going to be displayed in a listView in my android app.

What i want to know is what is the quickest way of linking the item clicked to its correct view, without having to type out each position in the array and have a serious of if statements which would take a year with this!

i dont want to be doing something like this

if(position == 1){
        setContentView(R.layout.bentleys);

as it would take a year doing that for each one...

Please help. thanks alot.

+1  A: 

You have a different layout for each restaurant? Typically you have one layout, and you fill in the unique information for each item in the array, i.e. set the text in a text area to the name of the array.

If you really have a unique layout for each, you could consider using some sort of naming convention to link them. Replace spaces with underscores, and lowercase everything.

Mayra
Definitely agreed. Having a different layout for each restaurant is very bad practice, while being a hassle for you to maintain and code, as well as being a bigger potential source of bugs
HXCaine
yeah i understood that after i had done out a load of layouts, but its too late to change it now unfort :(
Capsud