Android - how to add an item click method to an ArrayAdapter

前端 未结 3 1250
Happy的楠姐
Happy的楠姐 2021-01-12 03:11

I have a simple ArrayAdapter. I want to set up a listener for every row click of my list such that a new Activity opens. How would I do that? My ArrayAdapter code -

3条回答
  •  抹茶落季
    2021-01-12 03:36

    Simply implement AdapterView.OnItemClickListener.

    @Override
    public void onItemClick(AdapterView adapterView, View view, int pos, long l) {
        Intent i = new Intent(this, ProductActivity.class);
        i.putExtra("item_id", manager.getItemIdAtIndex(pos));
        startActivity(i);
    }
    

    Then just set the class with that method as the onItemClickListener in your adaptor.

提交回复
热议问题