The main problem here is that your custom OnClickListener
shouldn't extends Activity
because it isn't an Activity
. And such, it doesn't have the layout
that holds the id
s of the View
s you are trying to inflate.
This is why it crashes because you get a NPE
when trying to set the listener
on those View
s. You need to set the listeners
on them in your actual Activity
where you inflate the layout
with findViewById()
.
So, instead of having something like
myBtn.setOnClickListener(new View.OnClickListener());
you would have
myBtn.setOnClickListener(new MyOwnOnClickListener());
Edit
Try this, use the Context
from the View
passed in to get the other View
. I'm not positive this will work and I don't have time to test it at this moment but let's see.
public MyOwnOnClickListener(TextView id2, String id) {
myFirstButton = (Button) id2.getContext().findViewById(R.id.myFirstButton);
}