简体   繁体   中英

how to add/remove items in android Programmatically?

First, sorry for my bad English.

In my App I ask user to determine how many Imageview or Textview Or any Item they need. For example when at first, user opens the app he sees a button named "add album". then he clicks on it and chooses the name and the album button is created above of the "add" button.

After that user can go to the album and determine how many pages he need for his album. then in every page he can determine how many imagviews and textviews should be available in that specific page.

This is the App Idea and now I stuck in the first level. How can I do this add/remove function in code? for now I just can think of making the imagview nad textviews in the first and setting them "invisible" and when user selects "2 Image" I visible 2 Imagviews. Or doing this in the first page for adding Buttons in a list.

Is it the right way to do this?

No, the best way to add dynamic elements like this would be to use a listview or a gridview control for each item in listview or gridview you would define a layout that would include whatever controls you wanted.

Then to add x albums that are selectable (like a button) you would simply add x rows to the listview or gridview, which would show the controls you wanted. Listitems are clickable so they would behave as a button.

Its a bad idea to generate controls as you describe, but listviews and gridviews would be ideal for this situation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM