I've been trying to get button's onClickListener
working from inflated layout. I was trying this but nothing happens:
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.my_profile_fragment, null);
Button svBtn = (Button) view.findViewById(R.id.saveBtn);
svBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
System.out.println("CLICKED");
}
});
Inside the RecyclerView
adapter I inflate the original layout in onCreateViewHolder
which has the layout of the cards, and I am able to interact with it:
@Override
public ItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.single_card, null);
return new ItemRowHolder(v);
}
But I would like to interact with the button from a different layout (fragment layout). Is that possible, if so how can I achieve that?