Can not retrive data to another tab?

Olaan

Expert
Licensed User
Longtime User
Hi Klaus,and All
I use Corwin42's AHViewPager from Klaus 's hint and use Klaus 's ScrollView.
I can retrive data only the first tab,but I can not continue.,Please help me finished.

P.S. I'm not good at English,I use Thai Language in my widget

Best Regards ,and Thank you before
Theera
:eek:
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I had a look at your project.
Ffom what I see you have splitted the db.txt analysis int wo steps.
You should do all the analysis at once and work with the lists Plants, Questions and Answers as shown in one or your previous tests.
If you set a breakpoint at line 210 For i=1 To amt you'll see that the variable amt <> 0 and amt = 0 for all the next calls.

Best regards.
 
Upvote 0

Olaan

Expert
Licensed User
Longtime User
I had a look at your project.
Ffom what I see you have splitted the db.txt analysis int wo steps.
You should do all the analysis at once and work with the lists Plants, Questions and Answers as shown in one or your previous tests.
If you set a breakpoint at line 210 For i=1 To amt you'll see that the variable amt <> 0 and amt = 0 for all the next calls.

Best regards.

Hi Klaus,
I'm understand how to analysis at once. I tried to split Sub AddQuestions(Title) and move some code out of Sub CreatePanel(Title As String) As Panel. I don't know how make it work. I'm not good at programming.


Best Regards
Theera
 
Last edited:
Upvote 0

Olaan

Expert
Licensed User
Longtime User
Tabhost+Scrollview problem.

Hi Klaus,
I have studied your example already. In yours ,you know before only 2 tabs,but mine doesn't.
and try re-programming. I can't do about Tabhost+Scrollview.

Best Regards
Theera
 
Upvote 0

Olaan

Expert
Licensed User
Longtime User
Programming is not right

I had some time today and looked at your project.
Attached a modified version.

Best regards.

Hi Klaus,
Thank you very much for help,I must disturb you again,because programming is not right. My db.txt is shown only own of rice. not own of others. Each plants have more questions which are difference. Ofcause more anwers. If user check more than 1 question,the answer is linked of each answers with "+" ,but must be unique. All of plants have questions is not equal.

Format of db.txt is belows
[Rice]
question1 of Rice=Answer1 of question1
question2 of Rice=Answer2 of question2
...
questionN of Rice=AnswerN of questionN
[Flower]
question1 of Flower=Answer1 of question1
question2 of Flower=Answer2 of question2
...
questionN of Flower=AnswerN of questionN

Example1
Rice is header of tab is selected,question1 of Rice is checkbox ,question2 of Rice is checkbox,...,questionN of Rice is checkbox
The user can check more than 1 checkbox,and The answer is linked of each answer of them which checked with "+",but must be unique i.e. if the answer is a+b+c+b ,it 's changed be a+b+c

P.S. I'm sorry,I'm not good at both English and programming.

Best Regards
Theera
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Could you please explain exactly the structure of your db.txt file.
From what I have seen you have:
[Plant]
Question1 = Ansewer11 + Answer12 + Answer13
Question2 = Ansewer21 + Answer22
Question3 = Ansewer31 + Answer32 + Answer33
[Flower]
Question1 = Ansewer11 + Answer12
Question2 = Ansewer21 + Answer22 + Answer23

Are Ansewer11 + Answer12 + Answer13 considered as three answers or only as one answer ?
Where and how should the Answer(s) be displayed ?

Best regards.
 
Upvote 0

Olaan

Expert
Licensed User
Longtime User
Explained via pictures

Hi Klaus,
I try to make drawing, and explain 2 pictures. I hope you that understand me. I had ever use this code to keep questions of each plant.
Sub AddQuestions(Title As String)
Dim Rd As TextReader
Dim Wr As TextWriter
If Rd.IsInitialized=False Then
Rd.Initialize(File.OpenInput(File.DirAssets,"db.txt"))
End If
If File.Exists(File.DirDefaultExternal,"tmp.txt") Then
File.Delete(File.DirDefaultExternal,"tmp.txt")
End If
If Wr.IsInitialized=False Then
Wr.Initialize(File.OpenOutput(File.DirDefaultExternal,"tmp.txt",True))
End If
Dim RdLine As String
Dim chkStart As Boolean
Dim tmp As String
chkStart=False
RdLine = Rd.ReadLine
Do While RdLine <> Null
If (s.Left(s.Trim(RdLine),1) = "[" AND s.Right(s.Trim(RdLine),1) = "]") Then
tmp = s.Mid(s.Trim(RdLine), 2, s.Len(s.Trim(RdLine)) - 2)
If s.Trim(tmp)=s.Trim(Title) Then
chkStart= True
Else
If chkStart = True Then
Exit
End If
End If
Else
If chkStart= True Then
Wr.WriteLine(RdLine)
Else
Exit
End If
End If
RdLine =Rd.ReadLine
Loop
Rd.Close
Wr.Close

Questions.Initialize
Answers.Initialize
'Now we have a container with our panels just add it to the pager object
pager.Initialize(container, "Pager")

'As we want to show the tabs page indicator, we initialize it
fixedTabs.Initialize(pager)

Dim Rd1 As TextReader
If Rd1.IsInitialized = False Then
Rd1.Initialize(File.OpenInput(File.DirDefaultExternal,"tmp.txt"))
End If

amt=0
Dim lin As String
lin = Rd1.ReadLine
Do While lin <> Null AND lin <> ""
Dim str() As String
str = Regex.Split("=", lin)
Questions.Add(str(0))
Answers.add(str(1))
amt=amt+1
lin=Rd1.ReadLine
Loop
Rd1.Close



'********************
'Add Questions
ScrView1.Initialize(0)
Dim pnl As Panel
pnl=ScrView1.Panel
Activity.AddView(ScrView1,0, 90dip, Activity.Width, Activity.Height-138dip)
LstChk.Initialize

For i=1 To amt
Dim chk As CheckBox
chk.Initialize("")
chk.Text=Questions.Get(i-1)
LstChk.Add(chk)
pnl.AddView(chk,0,Hei*(i-1),200dip,Hei)
Next
pnl.Height=LstChk.Size*Hei

End Sub
Best Regards
Theera
 
Last edited:
Upvote 0

Olaan

Expert
Licensed User
Longtime User
Thank you,Klaus Your coding is better than my thinks. You are the king of great B4a programmer.

Best Regards
Theera
:icon_clap:
 
Upvote 0

Olaan

Expert
Licensed User
Longtime User
Disturb again please

Is this what you are looking for ?

Best regards.

Hi Klaus,

How to reset checkbox each plants after press "OK" button?
I need default is uncheck whenever press "OK" button
Best Regards
Theera
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Modify the btnAnswersOK_Click routine that way:
B4X:
Sub btnAnswersOK_Click
    Dim pnl As Panel
    pnl = container.GetPageObject(CurrentPage)
    Dim scv As ScrollView
    scv = pnl.GetView(0)
    Dim i As Int
    For i = 0 To scv.Panel.NumberOfViews - 1
        Dim chk As CheckBox
        chk = scv.Panel.GetView(i)
        chk.Checked = False
    Next
    
    pnlAnswers.Visible = False
End Sub
Best regards.
 
Upvote 0
Top