I am using GridLayout in my app and it works perfectly. Now I have to support android 3.xx as well, so I included android-support-library-v7. I just changed the import statements for GridLayout and LayoutParams at all places. I can build the project now but when I run the app, it crashes with NoSuchMethodError exception.
I followed these steps to include the support library
Here is the stacktrace:
03-27 13:37:13.454: E/AndroidRuntime(23016): FATAL EXCEPTION: main
03-27 13:37:13.454: E/AndroidRuntime(23016): java.lang.NoSuchMethodError: android.support.v4.view.ViewCompat.getLayoutDirection
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.isLayoutRtlCompat(GridLayout.java:675)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.getDefaultMargin(GridLayout.java:660)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.getMargin1(GridLayout.java:671)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout$Axis.computeMargins(GridLayout.java:1547)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout$Axis.getLeadingMargins(GridLayout.java:1558)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.getMargin(GridLayout.java:683)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.getTotalMargin(GridLayout.java:692)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.measureChildWithMargins2(GridLayout.java:897)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.measureChildrenWithMargins(GridLayout.java:911)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.support.v7.widget.GridLayout.onMeasure(GridLayout.java:950)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.measure(View.java:15848)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.measure(View.java:15848)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.HorizontalScrollView.measureChildWithMargins(HorizontalScrollView.java:1229)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.HorizontalScrollView.onMeasure(HorizontalScrollView.java:301)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.measure(View.java:15848)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.measure(View.java:15848)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.measure(View.java:15848)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.measure(View.java:15848)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.ListView.setupChild(ListView.java:1918)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.ListView.makeAndAddView(ListView.java:1843)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.ListView.fillDown(ListView.java:675)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.ListView.fillSpecific(ListView.java:1333)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.ListView.layoutChildren(ListView.java:1633)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.AbsListView.onLayout(AbsListView.java:2012)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.layout(View.java:14289)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.layout(ViewGroup.java:4559)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.layout(View.java:14289)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.layout(ViewGroup.java:4559)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.layout(View.java:14289)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.layout(ViewGroup.java:4559)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.layout(View.java:14289)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.layout(ViewGroup.java:4559)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.layout(View.java:14289)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.layout(ViewGroup.java:4559)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.View.layout(View.java:14289)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewGroup.layout(ViewGroup.java:4559)
03-27 13:37:13.454: E/AndroidRuntime(23016): at android.view.ViewRootImpl.perfor
EDIT: code
public class TableRenderingView extends GridLayout{
private Context mContext;
public TableRenderingView(Context context){
super(context);
mContext = context;
setUseDefaultMargins(true);
setAlignmentMode(ALIGN_BOUNDS);
setRowOrderPreserved(false);
}
...
}
Exception occurs when I try to add this extended class dynamically inside a LinearLayout
TableRenderingView trv = new TableRenderingView(context);
View v = trv.populate(gridRowData);
LinearLayout ll = ((LinearLayout) tableContainerView.getChildAt(0));
ll.removeAllViews();
ll.addView(v);