Open intent of a listview

1

I have a list of clients. I would like when I clicked on a client it would open a new intent. But I did something wrong. Here are the codes:

 list.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(ClienteActivity.this, DetalhesCatalogo.class);
            startActivity(intent);

        }

    });

}

When squeezing it it gives the following error:

09-16 13:13:25.047 1532-1532/com.example.jnior.decorus E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.jnior.decorus, PID: 1532
    *java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxxxxxxxxxxxxxxxxxxxxx.ClienteActivity}: 
    java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead*
    
asked by anonymous 16.09.2016 / 15:21

1 answer

4
list.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(ClienteActivity.this, DetalhesCatalogo.class);
            startActivity(intent);
        }
    });
}

setOnItemClickListener instead of setOnClickListener

    
16.09.2016 / 15:42