How do I add and remove views such as TextView
s from Android app like on the original stock Android contacts screen where you press a small icon on the right side of a field and it adds or deletes a field which consists of a TextView
and an editTextView
(from what I can see).
Any examples on how to achieve this?
// Now add xml main
// now add view xml file..
This is my general way:
Just use
myView.setVisibility(View.GONE);
to remove it completely. But if you want to reserve the occupied space inside its parent usemyView.setVisibility(View.INVISIBLE);
Hi You can try this way by adding relative layout and than add textview in that.
For Adding the Button
For removing the button
ViewGroup class provides API for child views management in run-time, allowing to add/remove views as well.
Some other links on the subject:
Android, add new view without XML Layout
Android Runtime Layout Tutorial
http://developer.android.com/reference/android/view/View.html
http://developer.android.com/reference/android/widget/LinearLayout.html