which is the right way to change the item height?
I tried this:
change from original 100dip item height to 200dip itemheight when the user click the item
But I get this error:
then I tried this and it worked:
Finally I tried this code and it does work fine, but it implies to REMOVE the panel and then insert the same panel again ( I dont like this method)
Is there a way to only change the item height without deleting and adding the same item?
Because while the program is deleting the old panel and adding the new one, it flashes the background color and does not look good for a good user experience.
Thanks.
I tried this:
change from original 100dip item height to 200dip itemheight when the user click the item
B4X:
Sub clv2_ItemClick(Index As Int, Value As Object)
Dim pnlnew AsPanel
Dim newvalue As Object
newvalue = Value
pnlnew= clv2.GetPanel(Index)
clv2.RemoveAt(Index)
clv2.InsertAt(Index,pnlnew,200dip,newvalue)
Log(Index & " = " & Value)
End Sub
But I get this error:
B4X:
LogCat connected to: 5718712f
--------- beginning of system--------- beginning of main~i:** Activity (main) Create, isFirst = true **~i:** Activity (main) Resume **
customlistview_insertat (java line: 242)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4212)
at android.view.ViewGroup.addView(ViewGroup.java:4065)
at android.view.ViewGroup.addView(ViewGroup.java:4041)
at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
at anywheresoftware.b4a.samples.customlistview.customlistview._insertat(customlistview.java:242)
at anywheresoftware.b4a.samples.customlistview.main._clv2_itemclick(main.java:389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:847)
at anywheresoftware.b4a.samples.customlistview.customlistview._panel_click(customlistview.java:388)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5197)
at android.view.View$PerformClick.run(View.java:20926)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
then I tried this and it worked:
B4X:
Sub clv2_ItemClick(Index As Int, Value As Object)
Dim newvalue As Object
newvalue = Value
pnlnew= clv2.GetPanel(Index)
clv2.RemoveAt(Index)
clv2.InsertAt(Index,CreateListItem($"Item #${Index+1}"$, clv2.AsView.Width, 100dip),200dip,newvalue)
Log(Index & " = " & Value)
End Sub
Finally I tried this code and it does work fine, but it implies to REMOVE the panel and then insert the same panel again ( I dont like this method)
B4X:
Sub clv2_ItemClick(Index As Int, Value As Object)
If clv2.GetPanel(Index).Height = 100dip Then
clv2.GetPanel(Index).Height = 200dip
SetItemHeight(200dip,clv2,Index,Value,clv2.GetPanel(Index))
Else
clv2.GetPanel(Index).Height = 100dip
SetItemHeight(100dip,clv2,Index,Value,clv2.GetPanel(Index))
End If
'SetItemHeight(200dip,clv2,Index,Value,clv2.GetPanel(Index))
Log(Index & " = " & Value)
End Sub
Sub SetItemHeight ( ItemHeight As Int, cv As CustomListView, index As Int, NewValue As Object, pnlnew As Panel) As Int
Dim spnlnew As Panel
Dim snewvalue As Object
snewvalue = NewValue
spnlnew = pnlnew
spnlnew.Height =ItemHeight
cv.RemoveAt(index)
spnlnew.RemoveView
spnlnew.LoadLayout("CellItem")
'spnlnew.Height = ItemHeight
cv.InsertAt(index,spnlnew,ItemHeight,snewvalue)
Return ItemHeight
End Sub
Is there a way to only change the item height without deleting and adding the same item?
Because while the program is deleting the old panel and adding the new one, it flashes the background color and does not look good for a good user experience.
Thanks.