android - Inflation of View Failing -


i've been trying programatically inflate linearlayout of buttons using loop, doesn't show in ui @ all. array gets populated, however.

my button xml:

<button xmlns:android="http://schemas.android.com/apk/res/android"     style="@style/blackkey"> </button> 

my style resource:

<style name="blackkey">     <item name="android:layout_height">0dp</item>     <item name="android:layout_width">match_parent</item>     <item name="android:layout_weight">2</item>     <item name="android:background">@color/black</item>     <item name="android:layout_margin">3dp</item> </style> 

my initialization code:

container = (framelayout) findviewbyid(r.id.mainframe); public button [] blackkeys = new button[5];  linearlayout blackkeys = new linearlayout(this); blackkeys.setlayoutparams(new linearlayout.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent)); blackkeys.setorientation(linearlayout.horizontal);  (int = 0; < 8; i++){     button newbutton = (button) layoutinflater.from(this).inflate(r.layout.blackkey, blackkeys, false);     blackkeys.addview(newbutton);     blackkeys[i] = newbutton; }  container.addview(blackkeys); 

so went ahead , tried code provided using android studio , have received blank screen. main point saw caused in blackkey style, layout_weight provided, layout_height set 0dp, , layout_width match_parent, orientation horizontal -- if ever button shows up, make show single button.

if how understood on how want show (five buttons alongside each other in horizontal orientation, equal widths) this:

enter image description here

then can modify blackkey styles this:

<style name="blackkey">         <item name="android:layout_height">wrap_content</item>         <item name="android:layout_width">wrap_content</item>         <item name="android:layout_weight">2</item>         <item name="android:background">@color/black</item>         <item name="android:layout_margin">3dp</item>     </style> 

and tip, if ever you're using android studio, can check first if button showing in design tab see if shows on screen. if doesn't show there, try modify it. hope helps you. if have further questions, or if similar answer you're looking not complete, post comment , i'll try out. :)


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -