Hello rajasharan
I saw this useful component and i want to use in my project.
In my case i want to add dynamic items, and i get an error.
This is my code:
public void addDynamicItemsToTableLayout ()
{
if (null == root)
{
root = (RearrangeableLayout) findViewById(R.id.rearrangeable_layout);
}
if (null == root)
{
Log.d(TAG, "RearrangeableLayout root is NULL");
return;
}
ImageView imgView = new ImageView(this);
imgView.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_send));
imgView.setLayoutParams(new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.WRAP_CONTENT));
//---------------------------
//-- Setting the position
//---------------------------
imgView.setX(200);
imgView.setY(300);
root.addView(imgView);
}
After executing that function i get the following error:
4-02 10:15:07.209 21223-21223/com.wci.cashregister E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ClassCastException: android.support.v7.widget.Toolbar$LayoutParams cannot be cast to com.wci.rearrangablelayout.RearrangeableLayout$LayoutParams
at com.wci.rearrangablelayout.RearrangeableLayout.onMeasure(RearrangeableLayout.java:125)
at android.view.View.measure(View.java:16195)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:786)
at android.view.View.measure(View.java:16195)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:16195)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16195)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16195)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16195)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2472)
at android.view.View.measure(View.java:16195)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2173)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1321)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1532)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1218)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4975)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5279)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
But then i changed Toolbar.LayoutParams to RearrangeableLayout.LayoutParams, but function signature are different, so compilation fails.
What could be causing this problem? I would appreciate your help.
Best Regards,
Carlos Mejia