android - LayoutParams returning null -


this code, dont know why returning null? can put null check here, there wrong?

    textview descriptiontv = (textview) findviewbyid(r.id.descriptiontv);     textview tc = new textview(c);     final popupwindow windowpopup = new popupwindow(tc,layoutparams.match_parent,layoutparams.wrap_content ,false);      tc.setbackgroundresource(r.drawable.bg_training_baloon_hc_2x);     tc.settext("this demo test check how looks, m wanting test whether works or not");     tc.setpadding(20, 20, 20, 20);     linearlayout.layoutparams params = new android.widget.linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content);     params.setmargins(30, 0, 30, 0);     tc.setlayoutparams(params); 

based on experience, have add view parent view first before can set layout parameters it, so:

textview calendaryear = new textview(getactivity()); calendaryear.settext(calendar.getyear() + ""); calendaryear.settextsize(20); calendaryear.settypeface(null, typeface.bold); calendaryear.setgravity(gravity.center); calendaryear.settextcolor(resources.getcolor(android.r.color.black)); calendaritemslinearlayout.addview(calendaryear);  // have add textview layout first before // can set layout margins viewgroup.layoutparams layoutparams = calendaryear.getlayoutparams(); ((linearlayout.layoutparams)layoutparams).setmargins(0, (int)(16 * density), 0, 0); calendaryear.setlayoutparams(layoutparams); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -