B4A Library [Library] B4aGridView v3.80

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi guys GridView has been updated to version 3.70, what's new:



//*********************************************************************************

added:

InitializeFromLayout("GridView",Activity,"main","gridView") (for this please have a look in the Maifest)

Friction (slow down the scroll)

AddThisView


ShowFromBucket (Depends On from new library B4AMediaBucket I'll upload till to night)

//*********************************************************************************

changed:

ShowText to TextVisible

//*********************************************************************************

important:
Work with Layout and as CustoView check it out.

minor bug fixed

tested on android 5.0.1, 6.0 and 7.1.1 samsung s4 tab1 tab2 tab10.1 and Huawei P8 Lite.

I uploaded 3 files a demo, library and a pdf
 

MarcoRome

Expert
Licensed User
Longtime User
Great work
Merry Christmas
 

aidymp

Well-Known Member
Licensed User
Longtime User
Well the first surprise is, IT WORKS!

And the second one is it works very well! If i use it, I will donate! but first impressions of 3.70 are very good!

Thanks!

Aidy
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi guys I forgot to say if U wish to Initialiize the GridView from layout You should write in the manifest example below:

B4X:
CreateResource(values, color.xml,

<resources>

    <color name="primary">#FF5722</color>
    <color name="primary_dark">#FF5722</color>
    <color name="sliddercolor">#50FF5722</color>
    <color name="back">#333333</color>

</resources>

)


to build your own gridview in the manifest as first you need this line below or U'll get an error

<it.giuseppe.salvi.gridview.library.core.gridview.GridViewCore



B4X:
CreateResource(layout, main.xml,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/sliddercolor"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical" >

<it.giuseppe.salvi.gridview.library.core.gridview.GridViewCore
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:cacheColorHint="#00000000"
    android:choiceMode="multipleChoice"
    android:columnWidth="100dp"
    android:drawSelectorOnTop="false"
    android:gravity="center"
    android:horizontalSpacing="2dp"
    android:listSelector="@android:color/black"
    android:numColumns="2"
    android:paddingLeft="1dp"
    android:paddingRight="1dp"
    android:paddingTop="2dp"
    android:stretchMode="columnWidth"
    android:verticalSpacing="2dp" />
 
</LinearLayout>

)


P.S

You can use any layout: ( LinearLayout, RelativeLayout, FrameLayout )

I wish you all a Merry Christmas

 
Last edited:

Ohanian

Active Member
Licensed User
Longtime User
Hi,

is it possible to add a ScrollChanged event to this lib?
 

Declan

Well-Known Member
Licensed User
Longtime User
Great Library, will definitely donate.
Two issues I cannot sort out.
I set ItemHeight / ItemWidth, but images are always square?
B4X:
    GridView.NumColumns = 3
    GridView.Itemwidth = 160dip
    GridView.ItemHeight = 210dip
    GridView.HorizontalSpacing = 50dip
    GridView.VerticalSpacing = 50dip
    GridView.Color = Colors.White
    GridView.SetBorderColor = Colors.White
    GridView.SetBorderWidth = 50dip
I need to read the filename of the image ("ugvuvu.jpg")
B4X:
Sub GridView_ItemClick(Position As Int, Value As Object)
    Log("Value: " & Value)
End Sub
gives me:
B4X:
Value: android.graphics.Bitmap@344ec3ea
 

Declan

Well-Known Member
Licensed User
Longtime User
Running V3.7, I get the following error.
Error is here:
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    Dim files As List
    If Permission = rp.PERMISSION_READ_EXTERNAL_STORAGE Then
        files = File.ListFiles(File.DirRootExternal & "/eBuki/BooksImages") 'get all files in this folder
        For i = 0 To files.Size - 1
            Dim f As String
            f = files.Get(i)
            If f.ToLowerCase.EndsWith(".jpg") Then
                MyBookImages.Add(f)
                GridView.AddImageAt(i, File.DirRootExternal, "/eBuki/BooksImages/" & f)
                GridView.TextVisible = True
                GridView.SetText2(i, f) '<--------ERROR
            End If
        Next
    End If
End Sub

My Code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    GridView.Initialize("GridView")
    GridView.AddThisView
    GridView.ShouldOnlyAnimateFling = True
    GridView.TransitionEffect = GridView.TransitionEffect.GROW
    GridView.ItemWidth = 320dip
    GridView.ItemHeight = 420dip
    GridView.HorizontalSpacing = 20dip
    GridView.VerticalSpacing = 50dip
    GridView.Gravity = Gravity.CENTER
    GridView.ColumnWidth = 160dip
    GridView.StretchMode = GridView.StretchMode.NO_STRETCH
    GridView.NumColumns = 3
    GridView.TransitionDuration = 400
    GridView.MaxAnimationVelocity = 300
    GridView.SimulateGridWithList = True
    GridView.ScaleType = GridView.ScaleType.Fit_Center
    GridView.CacheOnDisk = True
    GridView.CacheInMemory = True
    GridView.ProgressBarIndeterminate = False
    GridView.ProgressBarVisible = True
    GridView.Color = Colors.White
    GridView.SetBorderColor = Colors.White
    GridView.SetBorderWidth = 100dip
    MyBookImages.Initialize
  
    GridView.TextBackGroundColor2 = Colors.White
    GridView.TextBackGroundAlpha = 255
    GridView.TextLines = 1
    GridView.TextColor = Colors.Black'.LightGray
    GridView.TextPosition = GridView.TextPosition.Text_Bottom_OutSide
    GridView.TextSize = 20
    GridView.TextVisible = True

End Sub
Error:
B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 78 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.ArrayList.add(int, java.lang.Object)' on a null object reference
    at it.giuseppe.salvi.gridview.library.core.PhotoGridView.SetText2(PhotoGridView.java:1251)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$2.run(BA.java:328)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    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:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 

lonleystar

Well-Known Member
Licensed User
Longtime User

Hi I think U shold use GetRealImagePath or GetItem
 

cambopad

Active Member
Licensed User
Longtime User
Can I set custom folder for CacheOnDisk feature? For example, set it to Dir.rootExternal?
 

Marco Nissen

Active Member
Licensed User
Longtime User
Thanks, sorted.
how did you solve this ? I get the same error for the setText Method ..

Does anybody have an idea what's wrong?
urls is a list of image urls, and the images are loaded totally fine
however, I can't get the text to display

@lonleystar can you help?

B4X:
(NullPointerException) java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.ArrayList.add(int, java.lang.Object)' on a null object reference

B4X:
GridView.ShowFromWeb(urls,False)
j=0
For Each linkmap As Map In links
  Try
     Dim lname As String = linkmap.get("name")
     GridView.SetText2(j, lname)
  Catch
     Log("error" & LastException)
  End Try
  j=j+1
Next
 
Last edited:

Marco Nissen

Active Member
Licensed User
Longtime User
Hi guys I forgot to say if U wish to Initialiize the GridView from layout You should write in the manifest example below:
..
Unfortunately the demo app also doesn't work. I was hoping to download the demo app, and use it to place a comment below an image, but unfortunately after adding setText, it will crash with the error message ...

B4X:
GridView.SimulateGridWithList = True
GridView.ProgressBarIndeterminate = False
GridView.ProgressBarVisible = True
GridView.TextVisible=True
Try
    GridView.AddImageFromWeb("http://cdn4.spiegel.de/images/image-1098813-900_breitwand_180x67-lmhi-1098813.jpg")
    GridView.SetText("hello") 
Catch
    ToastMessageShow("issue " & LastException,True) 
EndTry

I would be more than happy to use this library, but there seems to be a major bug in setText, which prevents to use it.

Can you please provide a fix ?
I have a different implementation of a grid view which I did myself in my app, but I'd like to replace it with this library if possible.

Thanks
 

Marco Nissen

Active Member
Licensed User
Longtime User
It's the same error as above
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.ArrayList.add(int, java.lang.Object)' on a null object reference

I get it all the time .. let me know if you have a fix, it would be really super cool !
 

lonleystar

Well-Known Member
Licensed User
Longtime User

Hi just now I tried ShowFromWeb, AddImageFromWeb and AddImageFromWebAt work fine

did you check the image address maybe some address is null
 

Marco Nissen

Active Member
Licensed User
Longtime User
Hi just now I tried ShowFromWeb, AddImageFromWeb and AddImageFromWebAt work fine

did you check the image address maybe some address is null

Well, those methods are not the problem.

I can successfully display the image.

setText does not work.

As I described above, I modified the example that you provided to include "setText"

But: it creates the above error message.

I installed B4AGridView 3.70 and B4A 6.50

Any idea?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…