how can i use different activity for one listView

  • Thread starter Android Central Question
  • Start date
A

Android Central Question

hello . i created a listView with 40 items.
and i created 40 activity for that 40items.
but when i select every item ,just one activity starts.
how can i use special activity for special item.

thanks.
 

Taritz

Member
Nov 4, 2017
11
0
0
Visit site
It doesn't make sense when you say you have 40 activities for the 40 items in the listview. An Activity represents a single screen with a user interface, that covers the entire screen.

What you need to do is add a click listener to every item in the listview and handle the click in whatever way you like. If you expect to open a different Activity for every item, the easiest way would probably be to delegate the click event to the parent activity that holds the listview and have that handle the click events for the entire list, have a switch statement (or when if you're using Kotlin) and open the correct Activity for every separate item when clicked.

If you indeed have 40 different activities a better approach might be to just have the one activity and then just add fragments to it instead though.
 

Forum statistics

Threads
943,212
Messages
6,917,830
Members
3,158,883
Latest member
Abdul Ali