To call an Intent
in an adapter class in Android, you can use the context
object that is usually passed to the adapter's constructor to start the Intent
.
Here's an example of how you might do this in an adapter class:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private Context context; private List<Item> items; public MyAdapter(Context context, List<Item> items) { this.context = context; this.items = items; } // Other adapter methods public void onItemClick(int position) { Item item = items.get(position); Intent intent = new Intent(context, DetailActivity.class); intent.putExtra("item", item); context.startActivity(intent); } }Source:wtual.wwturi.com
In this example, the MyAdapter
class has a Context
object called context
and a list of Item
objects called items
. The onItemClick
method is called when an item in the adapter is clicked, and it starts an Intent
to open the DetailActivity
class, passing the clicked Item
object as an extra.