Skip to content

Add and remove views dynamically in Android, just like the original stock Android contacts app, where you and add and delete rows with animation.

Notifications You must be signed in to change notification settings

iamswapnilsonar/android-dynamic-views

 
 

Repository files navigation

Dynamically remove and add views in Android

This sample project achieves exactly the same functionality and look as the edit UI in the stock Android contact app (or "People"), where you can remove a row field view by pressing the "x" icon on the right, and add a row field view by pressing the "Add new" button at the bottom.

The example also handles some visibility logic for better UX as in the stock app: If a row becomes empty, "add new" and "x" will disappear.

Here is a demo video in action: http://www.youtube.com/watch?v=4HeqyG6FDhQ.

The state of the views is not saved for rotation. You'll need to work with onSaveInstanceState and onRestoreInstanceState. I left some notes in the code you can start with.

My original stackoverflow answer with some details: link

Key methods and classes used

TextWatcher, setVisibility, inflate, addView, removeView, animateLayoutChanges

About

Add and remove views dynamically in Android, just like the original stock Android contacts app, where you and add and delete rows with animation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published