Wish Support for Fragment-activities

DonManfred

Expert
Licensed User
Longtime User
in my wraps i did so far i found A LOT of libraries which all depends on

java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentManager android.support.v4.app.FragmentActivity.getSupportFragmentManager()' on a null object reference

B4X:
android.support.v4.app.FragmentActivity.getSupportFragmentManager()

The fragmentmanager of googlemaps seems to be not compatible to the fragmentmanager from android-support-v4 and the activity must be an FragmentActivity.

No one of the libs i wrapped works if they depends on the getSupportFragmentManager()

I wish someone could create an working java-code with a wrapper around the SupportFragmentManager() so i could use this then to finish all the libraries i have so far (all not working and not released).

Even in my newest wrap for the afollestad MaterialDialogs depends on supportFragmentManager for the Color picker and also for the file chooser dialog..
Both i can´t get to work :-(
 

DonManfred

Expert
Licensed User
Longtime User
You can use the #Extends attribute to make an Activity that extends FragmentActivity.
i tried it do to some minutes before i posted this thread. but with no success.

Note that i use a base example which is (and must be an appCompat activity for the MaterialDialogs (also for the MaterialDrawer)) an Appcompat activity.
So the activity is already
#Extends: android.support.v7.app.ActionBarActivity

Using both extends will not work as android.support.v4.app.FragmentActivity cannot be cast to android.support.v7.app.ActionBarActivity
 

DonManfred

Expert
Licensed User
Longtime User
And the next problem is to get the call to
B4X:
android.support.v4.app.FragmentActivity.getSupportFragmentManager()
inside the library itself (not my wrapper). I cant get any import to work which will result in returning a SupportFragmentManager
no such method getSupportFragmentManager()
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your class should be an @ActivityObject.
You can then do something like:
B4X:
void test(BA ba) {
 if (ba.activity instanceof android.support.v4.app.FragmentActivity == false)
  throw new RuntimeException("Activity must extend android.support.v4.app.FragmentActivity");
 FragmentActivity fa = (FragmentActivity)ba.activity;
 fa.getSupportFragmentManager()...
}
 

alimanam3386

Active Member
Licensed User
Longtime User
Coming soon ...

Demo


qweqwe.jpg


Main Activity:
B4X:
#Region  Project Attributes
    #ApplicationLabel: Amir_Fragment
    #VersionCode: 1
    #VersionName: 1.00
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

#Extends : android.support.v4.app.FragmentActivity

Sub Process_Globals
End Sub

Sub Globals
    Dim Content As Panel
    Dim Header As Panel
    Private SelectedFragment, ContentId As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Header.Initialize("")
    Activity.AddView(Header,0,0,100%x,56dip)
    Header.Color=Colors.White
    Header.Elevation=4dip
    Dim Titile As Label
    Titile.Initialize("")
    Header.AddView(Titile,24dip,0,150dip,56dip)
    Titile.TextColor=Colors.Black
    Titile.TextSize=20
    Titile.Text="Amir_Fragment"
    Titile.Gravity=Bit.Or(Gravity.CENTER_VERTICAL,Gravity.LEFT)

    Dim F1 As Label
    F1.Initialize("ShowFragment")
    F1.Tag=1
    Header.AddView(F1,100%x-112dip,0,56dip,56dip)
    F1.Typeface=Typeface.MATERIALICONS
    F1.TextColor=Colors.Black
    F1.TextSize=26
    F1.Text=Chr(0xE400)
    F1.Gravity=Gravity.CENTER
    Dim F2 As Label
    F2.Initialize("ShowFragment")
    F2.Tag=2
    Header.AddView(F2,100%x-56dip,0,56dip,56dip)
    F2.Typeface=Typeface.MATERIALICONS
    F2.TextColor=Colors.Black
    F2.TextSize = 26
    F2.Text=Chr(0xE401)
    F2.Gravity = Gravity.CENTER
   
    Content.Initialize("")
    Activity.AddView(Content,0,56dip,100%x,100%y-56dip)
    Content.Color = Colors.RGB(248,248,248)
   
    Dim FT As Amir_FragmentTransaction
    FT.Initialize
    ContentId = FT.GenerateViewId(Content)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub ShowFragment_Click
    Dim View As View = Sender
    Dim FragmentIndex As Int = View.Tag
    If FragmentIndex <> SelectedFragment Then
        Dim Fragment As Amir_Fragment
        Select FragmentIndex
            Case 1
                Dim First As FirstFragment
                First.Initialize
                Fragment = First.Fragment
            Case 2
                Dim Second As SecondFragment
                Second.Initialize
                Fragment=Second.Fragment
        End Select
        Dim FT As Amir_FragmentTransaction
        FT.Initialize
       
        FT.Replace(ContentId , Fragment)
        FT.Transition = FT.TRANSIT_FRAGMENT_OPEN
        FT.Commit
    End If
    SelectedFragment = FragmentIndex
End Sub

FirstFragment ( standard class )

B4X:
Sub Class_Globals
    Public Fragment As Amir_Fragment
    Dim Label As Label
    Public TAG As String = "First Fragment"
End Sub

Public Sub Initialize
    Fragment.Initialize("Amir","")
End Sub

Private Sub Amir_onCreateView (Parent As Panel)
    Parent.Width = 100%x
    Parent.Height = 100%y-56dip
    If Label.IsInitialized Then Return
    Label.Initialize("")
    Label.TextColor = Colors.Black
    Label.TextSize = 50
    Label.Text = TAG
    Label.Gravity = Gravity.CENTER
    Parent.AddView(Label, 0, 0, Parent.Width, Parent.Height)
End Sub

Private Sub Amir_onCreate
    LogColor(TAG & " Created",Colors.Yellow)
End Sub

Private Sub Amir_onPause
    LogColor(TAG & " Paused",Colors.Yellow)
End Sub

SecondFragment ( standard class )

B4X:
Sub Class_Globals
    Public Fragment As Amir_Fragment
    Dim Label As Label
    Dim Button As Button
    Public TAG As String = "Second Fragment"
End Sub

Public Sub Initialize
    Fragment.Initialize("Amir","")
End Sub

Private Sub Amir_onCreateView (Parent As Panel)
    Parent.Width = 100%x
    Parent.Height = 100%y - 56dip
    If Label.IsInitialized Then Return
    Label.Initialize("")
    Label.TextColor = Colors.Black
    Label.TextSize = 50
    Label.Text = TAG
    Label.Gravity = Gravity.CENTER
    Parent.AddView(Label,0,0,Parent.Width,Parent.Height)
   
    Button.Initialize("btn")
    Button.TextColor = Colors.Red
    Button.Text = "Click Me!"
    Button.TextSize = 16
    Parent.AddView(Button, 50%x-80dip, 80%y-28dip, 160dip, 56dip)
End Sub

Private Sub btn_Click
    ToastMessageShow("Button Clicked !",False)
End Sub

Private Sub Amir_onCreate
    LogColor(TAG & " Created",Colors.Red)
End Sub

Private Sub Amir_onPause
    LogColor(TAG & " Paused",Colors.Red)
End Sub
 
Top