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

you trying create list of items unknown #. way doing it, performance bad , inflating views linearlayout , not reusing views.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -