Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically creating a GridLayout from support library

In android, is it possible to create a GridLayout from the support library entirely programmatically (i.e. without writing corresponding xml)?

I create my GridLayout in a fragment (called PromotionLayoutFragment) like this:

ViewGroup fragmentView = (ViewGroup)getView(); 
GridLayout gridLayout = new GridLayout(fragmentView.getContext());
gridLayout.setColumnCount(2);
gridLayout.setRowCount(15);
// add views to grid ...
fragmentView.addView(gridLayout);

This works fine when i use the GridLayout class present in API level 14, but when I use the GridLayout from the support library (v7-r9), i get:

08-10 15:54:52.209: ERROR/AndroidRuntime(14687): FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:282)
    at net.link.redbutton.fragment.PromotionLayoutFragment.showPromotions(PromotionLayoutFragment.java:168)
    at net.link.redbutton.fragment.PromotionLayoutFragment.onImageResult(PromotionLayoutFragment.java:222)
    at net.link.redbutton.fragment.SchedulerResponseFragment$1.onReceiveResult(SchedulerResponseFragment.java:37)
    at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4441)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
like image 945
sgdesmet Avatar asked Aug 10 '12 16:08

sgdesmet


1 Answers

Turns out that you need to include the GridLayout support library as an Android library project (apklib), instead of a jar. I was using the maven Android SDK deployer, but there is currently an issue open regarding this.

like image 148
sgdesmet Avatar answered Nov 15 '22 00:11

sgdesmet