0

Okay, so I have an app with a few tutorials.(around 20) (Each tut is just some text filled in an activity screen)

I want to create a button on the main menu, that points to a listview activity containing the names of all the tutorial's activities - alphabetically.

Not perfect navigation, I know. But I think it's the best quick and easy solution till I learn more.

Here's the problem: I just want to say find out which listview item was clicked, and put a normal onclick() which opens up the corresponding tutorial activity.

How exactly do I set up the listview ? I know how the normal onclick works... but how to do it with a listview item ?

I came here from https://groups.google.com/forum/#!forum/android-developers

It said we can ask beginner questions here, but people seem to rather spend their precious time being mean. Is it really worth it ? If you know pls help me out. (A code example would be great, but any help would be appreciated)

Marek Sebera
  • 39,650
  • 37
  • 158
  • 244

2 Answers2

0

You have to use

listview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // start a new activity here        
        }
    });

where position is the position of the item in the list.

Alexander Pacha
  • 9,187
  • 3
  • 68
  • 108
shreyas
  • 2,166
  • 3
  • 18
  • 30
0

Take a look at this beautiful Introduction to Android ListViews. It contains extensive explanations and example source-code that can be downloaded.

Of course you can ask beginners question as long as they state a clear question to a problem that has not been solved many times before. If an answer to your question can be found by a simple web-search, you should do this research effort before asking it on Stackoverflow.

Alexander Pacha
  • 9,187
  • 3
  • 68
  • 108
  • Thank you, I was able to atleast get a list from this, Now reading up on the onclick().. –  Jul 19 '13 at 13:27