B4A Library MSDynamicGridView Library

Dave O

Well-Known Member
Licensed User
Longtime User
If you post the code in GetLayout and GetContent I can check and see if I can improve the performance.

Actually, it's quite smooth now that I'm caching the thumbnails in a map at the beginning:

B4X:
Sub generateSketchThumbnails
   thumbnailMap.Initialize
   Dim sketchPath As String = common.buildProtoFolderPath(common.currentProto.id, common.CURRENT_DATA_VERSION)
   For Each pageInstance As sketchPage In common.pageList
     Dim sketchName As String = common.buildSketchFileName(pageInstance.pageID)
     Try
       Dim tempBitmap As Bitmap
       tempBitmap.InitializeSample(sketchPath, sketchName, itemWidth, itemHeight)
       thumbnailMap.put(common.castToString(pageInstance.pageID), tempBitmap)
     Catch
       Msgbox("This page's sketch could not be thumbnailed: " & pageInstance.pageID, "generateSketchThumbnails")
     End Try
   Next
End Sub

...then fetching the thumbnail as needed:

B4X:
Sub adapter_GetContent(Position As Int, ItemID As Long, itemTag As String, contentPanel As Panel) As Panel
   contentPanel.SetBackgroundImage(thumbnailMap.Get(common.castToString(itemTag)))   
   Dim tempLabel As Label = contentPanel.GetView(0)
   tempLabel.Text = common.buildFullPageName(common.getPageFromID(itemTag))
   Return contentPanel
End Sub
 

Dave O

Well-Known Member
Licensed User
Longtime User
For double-click, I didn't want to add another listener for Gesture Detector (wasn't sure how nicely it would play with the gridview's listener), so I just watched the click event for successive taps within a short time period. A bit hacky, but it's simple and it works:

B4X:
Sub gridview_ItemClick(Position As Int)
   Dim tempId As Int = adapter.GetItemTagFromPosition(Position)
   If tempId = idClickedJustBefore Then      'interpret as a double-click
     doubleClickTimer.Enabled = False
     returnPageId = tempId                   'return to the double-clicked page
     okButton_Click
   Else
     idClickedJustBefore = tempId
     doubleClickTimer.Enabled = True
   End If
End Sub

Sub timer_Tick
   doubleClickTimer.Enabled = False
   idClickedJustBefore = 0
End Sub

And it makes for a nice shortcut. Otherwise, with no selection visible, it's not clear which page is being returned to.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
i dont know whethere there is a touchevent or not.
This java-code seems to do the wanted (i think it should work from reading the code)
Found here.
B4X:
public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if(firstTap){
                thisTime = SystemClock.uptimeMillis();
                firstTap = false;
            }else{
                prevTime = thisTime;
                thisTime = SystemClock.uptimeMillis();

                //Check that thisTime is greater than prevTime
                //just incase system clock reset to zero
                if(thisTime > prevTime){

                    //Check if times are within our max delay
                    if((thisTime - prevTime) <= DOUBLE_CLICK_MAX_DELAY){

                        //We have detected a double tap!
                        Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
                        //PUT YOUR LOGIC HERE!!!!

                    }else{
                        //Otherwise Reset firstTap
                        firstTap = true;
                    }
                }else{
                    firstTap = true;
                }
            }
            return false;
        }
 
Last edited:

asales

Expert
Licensed User
Longtime User
I tried to make an example (based in MultipleLayouts of MSDynamicGridView) to show the images of DirAssets, but don't work.

I get the error: "java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView"

I don't know how to modify the DA_GetLayout to fix it.

Please, see the example in attached.

I glad for any help.
 

Attachments

  • grid.zip
    61.4 KB · Views: 269

asales

Expert
Licensed User
Longtime User

I found the error!!!
I don't modify the DA_GetContent, that used a label from original example.

Solved with this code (until now):
B4X:
Sub DA_GetContent(Position As Int, ItemID As Long, ItemTag As String, ContentPanel As Panel) As Panel
    Dim iv1 As ImageView = ContentPanel.GetView(0)
    iv1.Tag = GridItems.Get(ItemID)
    Return ContentPanel
End Sub
 

asales

Expert
Licensed User
Longtime User
Now is a real issue:
I read the images of DirAssets but the order is missing when I scrolled the grid.

When start is ok (shows the images 0 to 7), but don't shows the images 8 and 9.
When I return to the top of grid the number is changed: 0 - 1 -> 1 - 0

I don't understand what is happening (new example and images in attached)?

 

Attachments

  • grid_2.zip
    62.5 KB · Views: 293

asales

Expert
Licensed User
Longtime User

Solved again with this code:
B4X:
Sub DA_GetContent(Position As Int, ItemID As Long, ItemTag As String, ContentPanel As Panel) As Panel
    Dim Bitmap1 As Bitmap
    Bitmap1.Initialize(File.DirAssets ,GridItems.Get(ItemID))    'relat_02

    Dim iv1 As ImageView = ContentPanel.GetView(0)
    iv1.Bitmap = Bitmap1

    Return ContentPanel
End Sub
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi @thedesolatesoul and All,

I wanted to use this library inside an item of Ultimate List view but i keep on getting Null Pointer exception. I want a grid view in the items. Is it possible for this to happen. I am trying to find alternatives.

Thank you for your kind attention.

Regards,
SK
 

thedesolatesoul

Expert
Licensed User
Longtime User
It should be possible to put it in there, but it wont scroll anymore.
I have to say it will be very tricky as you would have to Dim the gridview inside the LayoutCreator. Its possible that the adapter within adapter would cause a problem in re-drawing.
If you have a sample that demonstrates the issue we can try to see whats going on (if you think that is the correct solution for you).
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi @thedesolatesoul ,

I was able to integrate the grid view in the ULV item but is there a way I can get the height of the complete grid view? The GridView.Height is returning -1 even after the grid view is added.

Regards,
SK
 

thedesolatesoul

Expert
Licensed User
Longtime User
Hi @thedesolatesoul ,

I was able to integrate the grid view in the ULV item but is there a way I can get the height of the complete grid view? The GridView.Height is returning -1 even after the grid view is added.

Regards,
SK
Can you tell me how you add the grid to the ulv? ContentPanel.AddView?
[sorry im quite slow on responses these days]
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi @thedesolatesoul ,

I first added a panel in the layout creater of ULV to hold the entire grid view. Then in the content filler i added the gridview items. The images are loading properly but since the ULV picks up the scrolling function, the gridview images that are not displayed cannot be seen. Hence I wanted to change the height of of each item of ULV so that all complete gridview is seen but the gridview height is -1(fill parent).

Hope this helps.

Regards,
SK
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…