Does not recognize a ListView element

0

I'm creating a click event, for when pressed a certain LinearLayout that is in a ListView . The attributes of this ListView are in an XML ( item_list ), but it is not being able to fetch the linear to do the event, it is giving NullPointerException .

    ...
    listView.setAdapter(adapterListView);
    beber = (LinearLayout)findViewById(R.id.item_beber);
    beber.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            beberCerveja();
        }
    });

The error occurs on the 2nd row.

    
asked by anonymous 12.03.2014 / 14:12

1 answer

2

Use the setOnItemClickListener () method

listView.setAdapter(adapterListView);
listView.setOnItemClickListener(new View.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        beberCerveja();
    }
});
    
28.04.2014 / 15:35