开发者

Java & android: Help linking an item in a listView to its correct view, but not the way i know of

开发者 https://www.devze.com 2023-01-02 11:46 出处:网络
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[] {

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开发者_JAVA百科!

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号