Open Inside of a listview

Asked

Viewed 64 times

1

I have a list of customers. I would like when I click on a customer to open a new website. But I did something wrong. Follows the codes:

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

        }

    });

}

When I spin it makes the following mistake:

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*
  • 1

    Already in error: Don’t call setOnClickListener for an Adapterview. You probably want setOnItemClickListener Instead Do not call setOnClickListener. Calls setOnItemClickListener.

  • But then I have to change the code, because if you put setOnItemClickListener it gives error.

  • Look down there at the answer

  • just give listview.setOnItem (and hit enter that auto-complete android studio. then just put the Intent in the middle of the click)

  • Shut up man. Thank you. ABS.

  • brand as sure. I thank you.

Show 1 more comment

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.