Whats the best way to present a list to a user where each item on the list starts an Activity when selected?
I am on my first Android application and I am on a timeline so details and examples will be useful since my knowledge is still minimal.
I want my first screen to present the user with a list of activities to choose from. In my situat开发者_Python百科ion it is a recipe app where the user first chooses the type of food, such as, Beef, Chicken, or Pork. I want the application to launch an activity depending on the list item that the user clicked on.
I am not sure if I should use a list view, a text view, a scroll view, a list activity, an activity group... I need help please.
Thank you in advance!
I would suggest you use a ListActivity as your base class. As your class extends ListActivity you can use the event onListItemClick() to interpret the item the user clicks on and launch the appropriate intent.
You can bind your list to an Array of your foods. There are plenty of examples to be found how to construct the activity, just google for 'listactivity'
I was about to reply to your other post on using the arrays but it seems to have now disappeared.. so my reply to that post is below also
Create a second array that contains just your activity class names, So where you have
<string-array name="food_array">
<item> Beef</item>
<item>Chicken</item>
<item>Fish</item>
<item>Pork</item>
</string-array>
Also have a mirroring array that you can access e.g.
<string-array name="food_array_activities">
<item>BeefActivity.class</item>
<item>ChickenActivity.class</item>
<item>FishActivity.class</item>
<item>PorkActivity.class</item>
</string-array>
as your onItemClick gives you the position in the list that was clicked you can directly reference the second array to determine the activity name you should use.
Rgds
精彩评论