i have piece of code parsing xml values android activity, need show parsed xml values in 2 textviews in horizantal orientation programatically, values of each textview should in vertical orientation . got textviews in unstructured way. need show text views in structured way. can please me sort out problem. eg unstructured output:
flag false id 0 i need output
flag false id 0 i created textviews this
private void createtextview(string text, linearlayout root, int textsize, int width, int height, int gravity) { textview textview = new textview(context); linearlayout.layoutparams params = new linearlayout.layoutparams(width, height); if (gravity == gravity.right) { params.setmargins(300, 0, 0, 0); } if (gravity == gravity.left) { params.setmargins(150, 0, 0, 0); } if (gravity == gravity.center) { params.setmargins(20, 5, 0, 5); } textview.setlayoutparams(params); textview.settext(text); textview.settextsize(textsize); textview.setgravity(params.gravity); textview.settextcolor(context.getresources().getcolor( android.r.color.black)); root.addview(textview); } private void createtextviewswithhorizontalorient(string textone, string texttwo, linearlayout root) { linearlayout horizontallinearlayout = new linearlayout(context); linearlayout horizontalnextlinearlayout = new linearlayout(context); horizontallinearlayout.setorientation(linearlayout.vertical); horizontallinearlayout.setlayoutparams(new linearlayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content)); horizontalnextlinearlayout.setorientation(linearlayout.vertical); horizontalnextlinearlayout .setlayoutparams(new linearlayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content)); horizontalnextlinearlayout.setgravity(gravity.top); horizontallinearlayout.setgravity(gravity.top); createtextview(textone, horizontallinearlayout, 18, android.widget.linearlayout.layoutparams.wrap_content, android.widget.linearlayout.layoutparams.wrap_content, gravity.left); createtextview(texttwo, horizontalnextlinearlayout, 18, android.widget.linearlayout.layoutparams.wrap_content, android.widget.linearlayout.layoutparams.wrap_content, gravity.right); root.addview(horizontallinearlayout); root.addview(horizontalnextlinearlayout); } i got solution in method create textview change layout params
private void createtextview(string text, linearlayout root, int textsize,int width, int height, int gravity) { textview textview = new textview(context); linearlayout.layoutparams params = new linearlayout.layoutparams(100, height); createtextview(texttwo, horizontalnextlinearlayout, 18, android.widget.linearlayout.layoutparams.wrap_content, android.widget.linearlayout.layoutparams.wrap_content, gravity.left);
first of all, naming convention bad. have horizontallinearlayout has orientation set vertical.
secondly, assume root view linearlayout vertical orientation. it's obvious, output. should create onle 1 _horizontallinearlayout horizontal orientation. put 2 textviews in it, need play margin of second textview.
lastly, if you, create separate layout file 1 row (so horizontal linearlayout 2 textviews). positioning in xml, not in code. adding layout view:
view onewrow = activity.getlayoutinflater().inflate(r.layout.one_row, null, false); textview tv1 = onewrow.findviewbyid(r.id.textview1); textview tv2 = onewrow.findviewbyid(r.id.textview2); tv1.settext("flag"); tv2.settext("your value"); root.addview(onewrow);
Comments
Post a Comment