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 ?

ale
  • 6,369
  • 7
  • 55
  • 65
  • Your ListView contains an array of Activity names, right? Create another a corresponding array of Intents. When you find out the the position of the item in the list that's been clicked, start the corresponding Intent. – W.K.S Jul 19 '13 at 13:34
  • The above is a good solution if you're just getting started. A better solution is to subclass BaseAdapter. – W.K.S Jul 19 '13 at 13:34

1 Answers1

0

I am assuming you are using an adapter to load the content in the listview. You could just add an handler for individual row.

    public View getView(int position, View convertView, ViewGroup parent) 
    {
    View v = convertView;

            // Create your row layout
    if (v == null) {
        LayoutInflater vi = (  LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.your_layout,  parent, false);
    }


            // Set the click listener and handle
    v.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }

    });
     }
rydgaze
  • 1,050
  • 13
  • 24