Starting an activity after a listview item is clicked ?

  • Replies:2
Aditya Anand
  • Forum posts: 2

Jul 19, 2013, 1:04:05 PM via Website

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 ?

Reply
Bruno Apfelsini
  • Forum posts: 10

Jul 22, 2013, 12:41:49 PM via Website

setonitemclicklistener or onitemclick from listview

Reply
Ashish Tripathi
  • Forum posts: 211

Jul 24, 2013, 8:19:43 AM via Website

Hey,

To do this u can use list.setonitemclicklistener.

listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {


// position will tell you which item is clicked. now you want to open the corresponding activity. List has constant number of elements or it will vary. just explain this. if it's static list than you have the position and u can open the activity. if not than use some tricy logic.

Still problem share it

}
}

Reply