android - How to add several relativeLayout with 2 views inside programmatically? -
i took on stackoverflow can't find answer. add several rows (relativelayout
) parent (linearlayout
). relativelayout composed of 2 views, imageview
on left , textview
on right, both same row, each item:
linearlayout userlayout = (linearlayout) view.findviewbyid(r.id.participant_user); relativelayout rl = new relativelayout(context); relativelayout.layoutparams params = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content); params.addrule(relativelayout.align_left) (participant participant : participants) { textview textview = settextview(context, participant.getname()); rl.addview(textview, params); imageview imageview = new imageview(context); imageview.setimageresource(r.drawable.bz_ic_default_user); rl.addview(imageview, params); userlayout.addview(rl); }
it doesn't work, first element displayed or app crashed...
thank !
you should use listadapater or recylerview here
- https://developer.android.com/training/material/lists-cards.html
- http://developer.android.com/reference/android/widget/listadapter.html
you trying create list of items unknown #. way doing it, performance bad , inflating views linearlayout , not reusing views.
Comments
Post a Comment