You aren't quite using view stubs correctly...
First, point your view to the layout you desire for the view you want to duplicate by using this:
ViewStub stub = new ViewStub(this);
stub.setLayoutResource(R.layout.viewStubLayout);
stub.inflate();
Next, go into your XML and make sure the buttons on your layout have the android:onClick
option using the correct method, which is declared in your class.
For deleting view stubs, you don't actually delete them... you're supposed to use .setVisibility(GONE)
or .setVisibility(VISIBLE)
to manage if users can see it or not. This would be used in the method in which onClick
is directed to. Also, using "this
" when referring to the view stub your objects are in will allow you to manage what happens in the specified view the user clicks in.