Android Tutorial ActionBar / Sliding Pages tutorial

trueboss323

Active Member
Licensed User
Longtime User
Might be problematic. Did the ListView prevent the sliding from working properly?
Well here is the problem I have now. It seems that my list view gets cut off at the bottom of the screen. The code I have currently is:
B4X:
Dim height As Int = CalculateHeight(True, True)
Private vp As StdViewPager
    vp.Initialize("vp", 5, 100%x, height)


    Activity.AddView(vp.AsView, 0, 0, 100%x, height)

Sub CalculateHeight (TabsMode As Boolean, SplitEnabled As Boolean) As Int
   If 100%x >= 480dip Then
     Return 100%y
   Else
     Dim fix As Int
     If TabsMode Then fix = 48dip
     If SplitEnabled Then fix = fix + 48dip
     Return 100%y - fix
   End If
End Sub

I also tried replacing the height values to 100%y and tried using the AutoScale keyword in designer script, but I had no luck at all.
 

mrossen

Active Member
Licensed User
Longtime User
Hi

When I start my app I start to have 1 tab and I load 1 layout into panel(0)

B4X:
vp.Initialize("vp", 3, 100%x, height)
    Activity.AddView(vp.AsView, 0, 0, 100%x, height)
    'load the pages layouts
    vp.Panels(0).LoadLayout("0")

In tab1 I have a listview with a number of options. When I click the listview I add 2 more vp.panels and when I return to tab1 I remove the last 2 vp.panels

The problem is: When i try to slide page before I have clicked listview the code fails because I not have loaded the last 2 vp.panels.

The question is:

Should I : vp.Initialize("vp", 1, 100%x, height) at start and later change this to : vp.Initialize("vp", 3, 100%x, height) and how to do that?

or

Can I detect if a panel layout is loaded befor I try to slide the page

Mogens
 

mrossen

Active Member
Licensed User
Longtime User
Hi,

It is what I want to do.

When I then click the listview do I then have to vp.Initialize("vp", 3, 100%x, 100%y) to get 3 tabs

Do I have to to remove the activity and then do Activity.AddView(vp.AsView, 0, 0, 100%x, 100%y) Again.

I can not get this to Work properly,

Mogens
 

ttsolution

Member
Licensed User
Longtime User
Hi all,

How can I remove the bottom bar ? I want to maximize screen for another purpose

Many thanks

Jonh,
 

Taha

Member
Licensed User
Longtime User
Yesterday I upgraded my device to Android 5.0 and bar_ButtonClicked event not firing since then. Is there a workaround?
 

wildfandango

Member
Licensed User
Longtime User
Yes. Handle this event instead:
B4X:
Sub Activity_ActionBarHomeClick
  
End Sub

Thx 4 all Erel...

This Works fine for me (B4A 3.30)

Is possible change the left arrow icon showed with xx.ShowUpIndicator = True

For another picture...????

Thx in advance...
 

wildfandango

Member
Licensed User
Longtime User
Yes but in mi case, this is not a solution for 2 reasons:
  • NavigationMode=true Show a "ripple" effect on click
  • MOST IMPORTANT: NavigationMode=true works allways, the APP ico appears only under certain themes...
 

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello ;

I used your sliding panels. it is very good.
I added in tabs "control list view". so, it is not sliding with tabs.

1.steps: run app
2.steps : sliding with tabs cheked . its runnig
3.steps: click button "create list" on Panel2
4.steps: sliding with tabs cheked, so list is not move.

our full sample code is attachemnt.
where is the problem.


Note : ı used costum list view links
https://www.b4x.com/android/forum/t...ew-a-flexible-list-based-on-scrollview.19567/

i used acrtionbar sliding links:
https://www.b4x.com/android/forum/threads/actionbar-sliding-pages-tutorial.36865/#post-350067

full sample project
You can download it from address: http://s000.tinyupload.com/?file_id=04389155563947391584


screenshots:




'*************libraries****************
' contetn resolver
' CORe
' SQL
' stdActionbar
' stringutils
'*************libraries****************


B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
    'sh.Initialize
    cu.Initialize
    End If

    Dim height As Int = CalculateHeight(True, True)
    vp.Initialize("vp", 3, 100%x, height)
    Activity.AddView(vp.AsView, 0, 0, 100%x, height)
    'load the pages layouts
    vp.Panels(0).LoadLayout("0")
    vp.Panels(1).LoadLayout("1")
    vp.Panels(2).LoadLayout("2")
    bar.Initialize("bar")
    'bar.Icon = LoadBitmap(File.DirAssets, "giris.png")
    bar.NavigationMode = bar.NAVIGATION_MODE_TABS
    bar.AddTab("panel 0")
    bar.AddTab("panel 1")
    bar.AddTab("panel 2")
    bar.ShowUpIndicator = False' True
    bar.SelectedIndex = currentPage
    Activity.Title = "bu ana baslik"
    bar.Subtitle = "alt balikta bu"
 
    Activity.AddMenuItem3("", "mnuEdit", LoadBitmap(File.DirAssets, "ic_action_edit.png"), True)
    Activity.AddMenuItem3("", "mnuNew", LoadBitmap(File.DirAssets, "ic_action_new.png"), True)
    Activity.AddMenuItem3("", "mnuUndo", LoadBitmap(File.DirAssets, "ic_action_undo.png"), True)
    Activity.AddMenuItem3("Home", "ActionHome", LoadBitmap(File.DirAssets, "ic_action_undo.png"), True)
    Activity.AddMenuItem3("Search", "ActionSearch", LoadBitmap(File.DirAssets, "ic_action_undo.png"), True)
End Sub



...

B4X:
Sub Button1_Click
' cretae phobne list
    Rehber_yukleme
End Sub


Sub Rehber_yukleme
 
    '********************* SMS GÖNDERME VE ARAMA *****************************************
    'Dim xcall As PhoneCalls
    'Dim xsms As PhoneSms
    'xsms.Send("+905335135121","2 sistemm çalıstı")
    'Dim  sonuc As PhoneEvents
    'sonuc.Initialize("PE")
  
 
    'StartActivity( xcall.Call("02127711379"))
    '********************* SMS GÖNDERME VE ARAMA *****************************************
    'clv3.Initialize(Me, "clv3")
    clv3.Initialize(Me,"clv3")
    'clv3.Initialize(Panel_rehber,"clv3")
    'clv3.Initialize(vp.Panels(1),"clv3")
    Activity.AddView(clv3.AsView,0,Button1.Height , 100%x*0.90,100%y-Button1.Height-10)
    Dim reh_list As List
    reh_list.Initialize
    reh_list.Clear
    Dim adet As Int=cu.FindAllContacts(True).Size
    DoEvents
    Log (cu.FindAllContacts(True).Size)
    DoEvents
    Dim i As Int=0
    For Each c As cuContact In cu.FindAllContacts(True)
        reh_list.Clear
        For Each phone As cuPhone In cu.GetPhones(c.Id)
        'sb.Append(phone.Number & ", " & phone.PhoneType).Append(CRLF)
        reh_list.Add(phone.Number)
        Next
        i=i+1
        'clv3.Add(CreateListItem2( Rehber(i).isim, clv3.AsView.Width, 38dip,Rehber(i).telefon,i), 38dip, Rehber(i).id )
        DoEvents
        clv3.Add(CreateListItem2( c.DisplayName, clv3.AsView.Width, 38dip, reh_list,i ), 38dip, c.Id)
        'clv3.Add(CreateListItem2( Rehber(i).isim, clv3.AsView.Width, 38dip,Rehber(i).telefon,i), 38dip, Rehber(i).id )
    Next
 
End Sub


Sub CreateListItem2(Text As String, Width As Int, Height As Int, phonelist As List, index As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim b As Button
    b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
    Dim chk As CheckBox
    chk.Initialize("chk")
    Dim lbl As Label
    lbl.Initialize("etiket")
 
    Dim spn As Spinner
    Dim spn2 As Spinner
    spn.Initialize("spn")
    spn2.Initialize("spn2")
    spn.AddAll(phonelist)
    spn2.AddAll(Array As String("< YOK >","bey","hanım"))
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextSize = 16
    lbl.TextColor = Colors.White
    b.Text = "Click"
    chk.Tag=index
    spn2.Tag=index
    spn.Tag=index
 
    p.AddView(chk, 5dip, 2dip, 50dip, Height - 4dip) 'view #0
    p.AddView(lbl, 55dip, 2dip, 165dip, Height - 4dip) 'view #1
    p.AddView(spn, 220dip, 2dip, 170dip, Height - 4dip) 'view #2
    p.AddView(spn2, 390dip, 2dip, 150dip, Height - 4dip) 'view #3
    Return p
end sub
 
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings

I using the lib with two tabs, a data base and in the other a map (osm).
How eliminate the effect of manual displacement upon touching the screen (Sliding Pages), because it interfere with the displacement of the map, I have proven with:

sub bar_TabChanged (Index Int Ace, STab StdTab Ace)
Activity.RemoveAllViews........................

but removing the views, and pass of a to another tab , make my app that is slow or lost things.

thank you

I want to know if you have some code to could help me. thank you
 

Croïd

Active Member
Licensed User
Longtime User
Nexus 10

if I created a simple menu button (activity.addmenuItem("","") , and I selects, I get this error (ANR) .

Do you have a solution ?


 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
when I initialize the properties ".icon" and ".NavigationMode",
I've got these errors:


B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setIcon(android.graphics.drawable.Drawable)' on a null object reference


java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setNavigationMode(int)' on a null object reference

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