Reputation: 943
i am implemeting sample application in android for creating Dynamic Views.
Please observe below image............
By seeing the above picture i want to create a dynamic view it consists of close imageview, button, spinner and edittext by clicking Plus button. After entering all fields then i click on plus button create new view with above widgets similarly.
I want to delete particular row by clicking delete imageview. and again add by clicking plus, repeat this process untill how many rows we want. Then we click on submit button get all rows of views values and show those details on next screen....
And also tell me other way that is, Is there any possibility of create seperate xml file for that view and use it on our code...
Like see below picture...
Please help me.... Thanks in advance.....
Upvotes: 2
Views: 518
Reputation: 98
If you Store the Views in a iterable data structure like List, you could iterate over them when a "delete"-Button is klicked and search for the ones to delete by checking the coordinates by calling getX() and getY().
However, like lfor said before, the better way would be to create an own data structure for each row. I would recommend to create a "Row"-class containing the views you want to add per row including the "delete"-Button and passing the Activity you want to add the rows to as a reference. By doing so you can add the components for each row by calling the activity's method addContentView() inside the "Row"-class. Also you know which Views (all of the "Row"-Object you're in) you have to remove, when the delete button is pressed.
Upvotes: 1