0

I have a Linear layout and inside which there are few dropdown and text views,now i want to inflate the layout each time on click of "add more" button, below is the code for inflating the layout. the problem i am facing is to assign the id to each inflated layout content .Inorder to handle the content the inlfated layout i need the unique id for each content for each time i am inflating the layout.

LayoutInflater inflater = (LayoutInflater)   getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row_view;
row_view = (View)inflater.inflate(R.layout.inflatefloor,null);
                inflatefloordetails.addView(row_view);

here inflatefloor is the layout to inflate and inflatefloordetails is the main root layout inside which layout is to be inflated and i am inflating the inflatefloor layout each time on button click.

New to android pardon if anyone finds the question silly.

Note:Check out link below if anyone is facing similar problem, I found this link useful.

How to set Id of dynamic created layout?

Rocket
  • 11
  • 1
  • 5
  • I wouldn't do it like this, you should make a list. Check out [Recycler View.](https://developer.android.com/training/material/lists-cards.html) – Dillon Burton May 22 '17 at 06:03
  • @DillonBurton thanks for reply, but in my case list view or recycle view wont work. – Rocket May 22 '17 at 07:31
  • Can you please explain why? This sounds like the perfect instance for one, if I am understanding your question correctly. – Dillon Burton May 22 '17 at 07:34

1 Answers1

1

I think it will be helpful.

you can put any object when set the tag to be unique:

yourView.setTag(Object object);

and to retrive it:

object.indexOf(yourView.getTag())

Otherwise you have to use custom view.

Junaid Fahad
  • 149
  • 7