0
I’m creating an event of click, for when a particular LinearLayout
which sits on a ListView
. The attributes of this ListView
are in an XML (item_list
), but is not able to seek the linear to make the event, giving NullPointerException
.
...
listView.setAdapter(adapterListView);
beber = (LinearLayout)findViewById(R.id.item_beber);
beber.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
beberCerveja();
}
});
Error occurs on line 2.
I was able to solve the problem, just make the event click on Adapterlistview.
– user4647
As I understand it, this
LinearLayout
is inside an item of thisListView
, right? If so, you will only be able to seek theitem_beber
to set the click inside youradapterListView
, which is probably a class extending from aArrayAdapter
.– Paulo Rodrigues
second line for me is
beber = (LinearLayout) findViewById(R.id.item_beber);
and that doesn’t imply having to do the event elsewhere, and it just implies that you can’t locate the ID in its context, you can use namespace to do this without having to change anything :)– Paulo Roberto Rosa
It worked by putting in Adapterlistview, but this issue of namespace I did not understand, could explain me better?
– user4647