littlewombat littlewombat - 5 months ago 32
Java Question

Clickable LinearLayout in android studio

I want to use LinearLayot as a button, actually I have:

LinearLayout Ll;
Ll = (LinearLayout) findViewById(R.id.MYID);
Ll.setClickable(true);
Ll.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//action
}
});


but it doesn't work, when I try to open this activity is warning "Unfortunately, app has stopped". Click should close activity and back to main, in "//action" I use "finish()" but there is the same problem.

Answer

If you look at your code.

You are calling

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trainers);

after the linearlayout binding with click listener.

move these as the first line of the OnCreate

Comments