Simple list menu

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Simple list menu

Postby misterbo » Mon Sep 29, 2008 8:21 pm

What's the smartest way to build a list MENU (not necessarily dynamically ...) with ListActivity? The simple purpose would be to define a couple of list view items which start activities when they are being clicked, something like a table of content of my program.

I know, this looks like a very simple task - but unfortunatelly, I couldn't find any straight-forward sample for this.

Thanks a bunch!
boris
misterbo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Dec 31, 2007 4:13 pm

Top

Postby ninor » Mon Sep 29, 2008 9:08 pm

What kind of menu?
ContextualMenu (Long-press), OptionsMenu (MENU key) or simply a SubActivity?
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby misterbo » Tue Sep 30, 2008 8:35 am

Hi,

thanks for your reply! In fact, I'd like to implement a menu like the one from the API demos (see screenshot) but not in the same, dynamical way (if I remember well their menu is generated from the structure of the file system ...).

Kind regards,
boris
Attachments
menu.jpg
menu.jpg (52.96 KiB) Viewed 2699 times
misterbo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Dec 31, 2007 4:13 pm

Postby ninor » Tue Sep 30, 2008 10:42 am

Well, then it's very simple

Create the static XML layout that you desire, put IDs to every widget/component.
Create a new Activity.
In onCreate associate the IDs to components in the XML.
At the end of onCreate, set your setContentView(R.layout.yourxmllayout)

Now, inside the onCreate, this is what I'm not very sure: you have to override the onClick of every item, or the onClick for the whole activity. You can try.

And another solution, could be this one:

http://www.anddev.org/touchable_listview-t2586.html

This method should be simpler, but maybe it's too dynamic for your tastes :lol:
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby misterbo » Tue Sep 30, 2008 11:02 am

Thanks again for answering. I perfectly understand your post for the case of, let's say, buttons. However, in this particular case I'd like to use ListView with respective list elements. Is there any "ListViewItem" element I could populate the ListView in my static XML layout with?

Cheers,
boris
misterbo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Dec 31, 2007 4:13 pm

Postby ninor » Tue Sep 30, 2008 11:21 am

Then there are 2 solutions that I know:
1) Do it in java code.
2) If we read ListView widget in Android Docs, it refers to a ListAdapter, which "is the bridge between a ListView and the data that backs the list" http://code.google.com/android/reference/android/widget/ListAdapter.html
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests