android - removeAllViews not removing view completely -


i having problem removeallviews() method. can see in pictures, still has 2 textviews empty, still creating empty space in layout makes bad.

http://jacho981.hol.es/screenshot_2014-04-22-11-55-12.png

as can see in next picture, textviews should disappearing in previous picture, used in one.

http://jacho981.hol.es/screenshot_2014-04-22-11-55-19.png

everytime press "moto" or "coche" butons, first method called removeallviews() on linearlayout holds views. in theory views created if objects contains in string.

in case removeallviews working properly, don't understand why it's creating textviews, in if sentence (the removeallviews() method called before sequence of if sentences next one):

    // cober_title                                                 if (listaseguros                                                         .get(j)                                                         .getseg_cober_title() != null                                                         || listaseguros                                                                 .get(j)                                                                 .getseg_cober_title() != "") {                                                     textview tv_seg_cober_title = new textview(                                                             getactivity());                                                     tv_seg_cober_title                                                             .settext(listaseguros                                                                     .get(j)                                                                     .getseg_cober_title());                                                     tv_seg_cober_title                                                             .setallcaps(true);                                                     tv_seg_cober_title                                                             .settextcolor(color                                                                     .parsecolor("#275880"));                                                     tv_seg_cober_title                                                             .settextsize(                                                                     typedvalue.complex_unit_sp,                                                                     26);                                                     tv_seg_cober_title                                                             .setgravity(gravity.center_horizontal);                                                     linearlayout.layoutparams params = new linearlayout.layoutparams(                                                             new layoutparams(                                                                     layoutparams.match_parent,                                                                     layoutparams.wrap_content));                                                     params.setmargins(10,                                                             10, 10, 10);                                                     tv_seg_cober_title                                                             .setlayoutparams(params);                                                     content_frame_seguros                                                             .addview(tv_seg_cober_title);                                                 } 

so in case string variable seg_cober_title null or empty, textview shouldn't created @ all... @ least that's can't understand.

thisis messing how app looks. appreciate all!

ps: if want me post more code will, didn't want fill codelines.

thanks!!

you have 2 mistakes. condition true.

(listaseguros.get(j).getseg_cober_title() != null || listaseguros.get(j).getseg_cober_title() != "")

because second condition listaseguros.get(j).getseg_cober_title() != "" true, if real contains empty string. read how compare objects in java. (you must use equals() method of string instead of "!=".

and second mistake "||". it's "or", need "and" ("&&"). if title equals null, it's not equals empty string , whole condition true. false if title null , empty string simultaneously.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -