SlidingPanel example.. layout not showing.

Beja

Expert
Licensed User
Longtime User
Hi friends,

A very nice and extremely usful example, that can be applied to virtually any kind of project.. thanks Erel.. only I am not seeing the layouts in designer. now I don't know how to add views to the 3 panels.. (I always use the designer because it is easier and fast).

Please help and thanks in advance.
 

Beja

Expert
Licensed User
Longtime User
Erel please pardon me asking so simple questions.
In the designer window I couldn't see any layout filename. how can I locate those file and how can add them.. steps please! :sign0085:
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
In a new project I visually place views on the activity or panel then save the layout.. and then when I open the project again the layout is there.. but here there is nothing in the desinger window.. just a blank small window.. yes I can save it and give it a name but the same blank windows comes back..
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code in the example creates the panels:
B4X:
Dim panels(3) As Panel
For i = 0 To panels.Length - 1
   panels(i).Initialize("panels")
   panels(i).Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
   Dim lbl As Label
   lbl.Initialize("")
   lbl.Text = "I'm Panel: " & i
   lbl.TextSize = 20
   lbl.TextColor = Colors.White
   panels(i).AddView(lbl, 20%x, 40%y, 60%x, 30dip)
   Activity.AddView(panels(i), 100%x, 0, 100%x, 100%y - 60dip) 'add the panel to the layout
   Activity.AddMenuItem("Panel #" & i, "Menu")
Next

Instead of adding a label you can use:
B4X:
panels(i).LoadLayout("your layout file")
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
B4X:
panels(i).LoadLayout("your layout file")

mine?
Where is it, Erel? layout elements are in code.. but I don't see any layout file in the project directory.. how can I create it?
 
Last edited:
Upvote 0

manasak19

Member
Licensed User
Longtime User
How to Random Question?

Help me please..:sign0085:
I have 100 questions. <How to write code random in 100 question > and Random in choice <A,B,C,D,E>

1. sdfashdfjafdjdh
A. KJKD
B. DFDK
C. SDFAL
D. SSLDJF
E. DFASDFA

2. SDFLSAKFDSLDKFAJ
A.FSDFAFD
B. SDFASDF
.....................

choice Answer A. True Score 1

Help me please...
Thank you very everybody for answer me...
Mr.Manasak
From Thailand <[email protected]>
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
welcome to B4A world!

open new thread for this question
 
Last edited:
Upvote 0

Beja

Expert
Licensed User
Longtime User
Finally the problem is solved.. thanks.

for those are interested to know how I did it, just added a "T" in the beginning and replaced the last "D" with a "T", and it became Static panels, instead of Sliding panels.
Thanks Erel for the sincere willing to help and don't want to waste more of your time.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
I have 100 questions. <How to write code random in 100 question > and Random in choice <A,B,C,D,E>

1. sdfashdfjafdjdh
A. KJKD
B. DFDK
C. SDFAL
D. SSLDJF
E. DFASDFA

2. SDFLSAKFDSLDKFAJ
A.FSDFAFD
B. SDFASDF
.....................

choice Answer A. True Score 1

Alright, I don't see you opened new thread.. and since my question is no more may be I can offer you an idea.. and I would suggest to you to use adaptive algorithm instead of this straightforward approuch. The way you defined above is old and modern test software are using adaptive methods, to reduce test time.. both the smart and not-so-smart students will finish the test quickly, your software will let the smart jump easy questions depending on their answers to the first ones, while the not-smart will also save time because they will be explled from the classroom earlier because your software will determine no need to their continuation!
You can create two more objects.. call the first smartness and the second stupidity. Also your software should be smart and recognize random andswers in multi-choice questions.. there are techniques to do so.

hopefully this will help you
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I understood your question in this thread.
You can create one layout file for each Panel in the Designer.
And load these files in the code as Erel already suggested.

Attached Erel's example with layout files.

Best regards.
 

Attachments

  • SlidingPanels1.zip
    11.1 KB · Views: 477
Upvote 0

adalexander

Member
Licensed User
Longtime User
You need to load the layout files to the panels (Panel.LoadLayout).
Erel Hello, I understand you are poor, but I can not understand why those who ask simple things come to me impossible things before I asked for something to make a simple vertical ScrollView I had to give impossible, I had about 30 images on the first page, I had to do otherwise, then I followed the tutorial on the panels if I take the example does not come out of nowhere, now I need to insert the panels do not know how to do, I have a screen with a menu where there are 12 entries under each of which is attached to a webview of my site, working with the activity is a long process and i have to open too many screens, I wanted to learn better with the panels, but i can not find a valid driver, examples, unfortunately i will have to refrain from using this program for me is too difficult , excuse my english, I'm trying to learn that too, it takes a bit of patience, thank you.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi Klaus,
Thanks so much for your help, and I am sorry I just saw this after the post was resurrected :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@adalexander
What exactly do you want to do ?
I have read severel of your posts also in the italian forum but still don't understand what you want to do and what you have tried.
You say things don't work but unfortunately you don't show any code with a clear explanation on what you have done, what doesn't work and what you expect.
Post your test project as a zip file (IDE menu Files / Export As Zip) so we could help you.
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
I understood your question in this thread.
You can create one layout file for each Panel in the Designer.
And load these files in the code as Erel already suggested.

Attached Erel's example with layout files.

Best regards.
Is it possible to load panels through JSON, I am trying but getting error:

B4X:
java.lang.RuntimeException: Object should first be initialized (List).


    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
    at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
    at com.sidso.islah.allah_names._activity_create(allah_names.java:349)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at com.sidso.islah.allah_names.afterFirstLayout(allah_names.java:98)
    at com.sidso.islah.allah_names.access$100(allah_names.java:16)
    at com.sidso.islah.allah_names$WaitForLayout.run(allah_names.java:76)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)


    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized (List).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is it possible to load panels through JSON, I am trying but getting error:

B4X:
java.lang.RuntimeException: Object should first be initialized (List).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
    at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
    at com.sidso.islah.allah_names._activity_create(allah_names.java:349)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at com.sidso.islah.allah_names.afterFirstLayout(allah_names.java:98)
    at com.sidso.islah.allah_names.access$100(allah_names.java:16)
    at com.sidso.islah.allah_names$WaitForLayout.run(allah_names.java:76)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)


    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized (List).

Without seeing any code you are using it is like guessing...

The LIST-object which you are accesing is not initialized. Initialize the list before using it.
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
Without seeing any code you are using it is like guessing...

The LIST-object which you are accesing is not initialized. Initialize the list before using it.
Got it fixed, it was a school boy error, I was initializing the sliding panel similar to custom list view which was giving the LIST initialization error. I just moved the JSONParse code within for LOOP and it worked. Here is the working code if someone else might need it.

B4X:
Dim panels(11) As Panel
    For i = 0 To panels.Length - 1
    panels(i).Initialize("panels")
    panels(i).Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
    panels(i).LoadLayout("pnames")
    Dim parser As JSONParser
    parser.Initialize(File.ReadString(File.DirAssets, "Allah_names.json"))
    Dim root As Map = parser.NextObject
   
    Dim names As List = root.Get("names")
    Dim actname As Int = -1
    For Each colname As Map In names
        actname = actname+1
        If actname = i Then
            Dim getNum As String = colname.Get("NameNum")
            Dim GetName As String = colname.Get("Name")
            Dim GetTranslit As String = colname.Get("translit")
            Dim GetTranslat As String = colname.Get("translat")
           
            Num.Text = getNum
            Name.Text = GetName
            Translit.Text = GetTranslit
            Translat.Text = GetTranslat            
        End If
    Next       
   
    pView.AddView(panels(i), 100%x, 0, 100%x, 100%y - 60dip)   
           
    Next
    btnLeft.Initialize("Left")
    btnLeft.Text = "Next"
    Activity.AddView(btnLeft, 70%x, 100%y - 55dip, 100dip, 50dip)
    btnRight.Initialize("Right")
    btnRight.Text = "Back"
    Activity.AddView(btnRight, 50%x, 100%y - 55dip, 100dip, 50dip)
   
    sd.Initialize
    sd.panels = panels
    SlidingPanels.Initialize(sd, SlidingDuration)
    sd.targetPanel = -1
    sd.currentPanel = currentPanelBeforePaused - 1
    ChangePanel(True) 'Current code expects the first call to be with Left = True.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello Runo,

You can .BringToFront or .SendToBack which changes the Z order of the Panel
 
Upvote 0
Top