Android Question BCTextEngine/BBCodeview can't handle looping from MYSQL database

omo

Active Member
Licensed User
Longtime User
How can one display all records from Mysql database in BBcodeview ?. I don't know why BBcodeview can't display all records from MYSQL and PHP database or am i the one who is not handling it well?. I have used different approaches, but each ended up displaying only last record in bbcodeview. I used knowledge from B4Xtable, Mysql and Php, but still ended up displaying last record only. The program itself is very huge, but i have attached a simple demo consisting just three fields to demonstrate problem i am talking about. B4A, PHP, Mysql.sql and mysql.txt is in the zipped folder below to make it simpler for people to setup and handle; log(jb.GetString) and log(list1.size) show that all records were returned. I also put spinner to receive all returned record, but BBcodeview could only display last record only. Please, help me




Problem With BBCodeview Displaying All Record from Mysql:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Public name, country, status As String
    Private Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("bblooptest2")
    TextEngine.Initialize(Activity)
    'BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\{}" & TAB & CRLF & Chr(13)
    BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    
    BBCodeView1.sv.ScrollViewOffsetY = 0
    
    'This adds button to bbcodeview
    Dim btn1 As Button
    btn1.Initialize("btn1")
    'btn2.Text = Chr(0xF04B) '"Play"
    #if B4i
    Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
    FontSize = 12
    #else
    btn1.Initialize("btn1")
    #End If
    Dim x As B4XView = btn1
    'x.Font =  xui.CreateFontAwesome(28)
    x.TextSize = 12
    x.Text = "View Answer" 'Chr(0xF04B)
    x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
    x.TextColor = Colors.DarkGray
    x.Color = Colors.LightGray
    'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
    x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)
    
    BBCodeView1.Views.Put("btn1", btn1)
    
    Dim jb As HttpJob
    jb.Initialize("sch2", Me)  'https://mftp.infinityfree.net
    jb.Download2("http://192.168.43.47/schphp.php", Array As String("action","sch2"))
    Wait For (jb) JobDone(jb As HttpJob)
    If jb.Success Then
            Dim parser As JSONParser
        parser.Initialize(jb.GetString)
    
        Select jb.jobname
    
            Case "sch2"
                
                'let list handle parser by declaring list
                Dim list1 As List
                list1.Initialize
                list1 = parser.NextArray 'json will extract data from json and store them as list
               
                If list1.Size = 0 Then
                    MsgboxAsync("not successful", "Not Successsful")
                Else
                    For i = 0 To list1.Size - 1
                        'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country")
                        status = user_map.Get("status")
                        Spinner1.Add(name)
                    
        BBCodeView1.Text = _
   $"[Color=#ff0000][TextSize=17][Alignment=left][b]${name}${CRLF}${country}${CRLF}${status}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]
   "$
                    
                    Next
                End If
                  
        End Select
        
    Else
        Log("Error!")
    End If
    jb.Release
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Here is Php code Used (Don't worry about security issue, I have handled that in my main project):
<?php
$servername        = 'localhost';
$username        = 'root';
$password        = '';
$dbname    = 'sch';

$action = $_GET["action"];


$link = mysql_connect($servername,$username, $password) or die(mysql_error());
mysql_select_db($dbname, $link);


switch ($action) 
{
                       

     case "sch2":
      
      
                                     
                      $sql3 = "Select * FROM sch1";
              $result = mysql_query($sql3) or die(mysql_error());
                      $rows = array();
              while ($row = mysql_fetch_assoc($result)) {
            $rows[] = $row;
                      
                      }
                   
                      print json_encode($rows); 
                      break;

}    
    
Mysql_close();
?>[CODE lang="b4x" title="Here is my Mysql database(just to show the problem)"]
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `sch`
--

-- --------------------------------------------------------

--
-- Table structure for table `sch1`
--

CREATE TABLE `sch1` (
  `name` varchar(50) NOT NULL,
  `country` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `sch1`
--

INSERT INTO `sch1` (`name`, `country`, `status`) VALUES
('University of Lagos', 'Nigeria', 'Approved'),
('Harvard University', 'USA', 'Approved'),
('MIT', 'USA', 'Approved'),
('University of Ibadan', 'Nigeria', 'Approved');
[/CODE]

Here is the result of simple demo
resultpic.png
 

Attachments

  • testbbcodeloop.zip
    11.8 KB · Views: 212

toby

Well-Known Member
Licensed User
Longtime User
try

B4X:
    For i = 0 To list1.Size - 1
      
     Private BBCodeView1 As BBCodeView

     BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    BBCodeView1.sv.ScrollViewOffsetY = 0
 
    'This adds button to bbcodeview
    Dim btn1 As Button
    btn1.Initialize("btn1")
    'btn2.Text = Chr(0xF04B) '"Play"
    #if B4i
    Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
    FontSize = 12
    #else
    btn1.Initialize("btn1")
    #End If
    Dim x As B4XView = btn1
    'x.Font =  xui.CreateFontAwesome(28)
    x.TextSize = 12
    x.Text = "View Answer" 'Chr(0xF04B)
    x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
    x.TextColor = Colors.DarkGray
    x.Color = Colors.LightGray
    'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
    x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)
 
    BBCodeView1.Views.Put("btn1", btn1)

     'your existing code:
    'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country
     ''''''''
   Next
 
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
try

B4X:
    For i = 0 To list1.Size - 1
     
     Private BBCodeView1 As BBCodeView

     BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    BBCodeView1.sv.ScrollViewOffsetY = 0

    'This adds button to bbcodeview
    Dim btn1 As Button
    btn1.Initialize("btn1")
    'btn2.Text = Chr(0xF04B) '"Play"
    #if B4i
    Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
    FontSize = 12
    #else
    btn1.Initialize("btn1")
    #End If
    Dim x As B4XView = btn1
    'x.Font =  xui.CreateFontAwesome(28)
    x.TextSize = 12
    x.Text = "View Answer" 'Chr(0xF04B)
    x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
    x.TextColor = Colors.DarkGray
    x.Color = Colors.LightGray
    'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
    x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)

    BBCodeView1.Views.Put("btn1", btn1)

     'your existing code:
    'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country
     ''''''''
   Next
Hello, toby, thank you for trying to help. I tried based on your suggestion, but was not even running; it was raising error issues. the structure i used above retrieved all records from mysql database, one can see this if you put sleep(1500) just before next statement after bbcodeview statement. But the problem is that instead of displaying all the four in BBCodeview one after the other, it ends up displaying all records in the same place, so that only the last record will be seen on top. This is how i implemented your suggestion that raised error:
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    'Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Public name, country, status As String
    Private Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("bblooptest2")
    TextEngine.Initialize(Activity)
    'BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\{}" & TAB & CRLF & Chr(13)
    
    
    Dim jb As HttpJob
    jb.Initialize("sch2", Me)  'https://mftp.infinityfree.net
    jb.Download2("http://192.168.43.47/schphp.php", Array As String("action","sch2"))
    Wait For (jb) JobDone(jb As HttpJob)
    If jb.Success Then
            Dim parser As JSONParser
        parser.Initialize(jb.GetString)
    
        Select jb.jobname
    
            Case "sch2"
                
                'let list handle parser by declaring list
                Dim list1 As List
                list1.Initialize
                list1 = parser.NextArray 'json will extract data from json and store them as list
               
                If list1.Size = 0 Then
                    MsgboxAsync("not successful", "Not Successsful")
                Else
                    For i = 0 To list1.Size - 1
                    
                        Dim BBCodeView1 As BBCodeView
                        BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    
                        BBCodeView1.sv.ScrollViewOffsetY = 0
    
                        'This adds button to bbcodeview
                        Dim btn1 As Button
                        btn1.Initialize("btn1")
                        'btn2.Text = Chr(0xF04B) '"Play"
    #if B4i
    Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
    FontSize = 12
    #else
                        btn1.Initialize("btn1")
    #End If
                        Dim x As B4XView = btn1
                        'x.Font =  xui.CreateFontAwesome(28)
                        x.TextSize = 12
                        x.Text = "View Answer" 'Chr(0xF04B)
                        x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
                        x.TextColor = Colors.DarkGray
                        x.Color = Colors.LightGray
                        'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
                        x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)
    
                        BBCodeView1.Views.Put("btn1", btn1)
                    
                    
                        'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country")
                        status = user_map.Get("status")
                        Spinner1.Add(name)
                    
        BBCodeView1.Text = _
   $"[Color=#ff0000][TextSize=17][Alignment=left][b]${name}${CRLF}${country}${CRLF}${status}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]
   "$
                    
                    Next
                End If
                  
        End Select
        
    Else
        Log("Error!")
    End If
    jb.Release
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I simplified your code by using demo data instead mysql one. The attached app is able to show all 3 records. You can take a look to see if this is what you want.



B4X:
    Dim str As String
    For i = 0 To 2
        'We can now define map to hold each colum of our tables
        'Dim user_map As Map
        'user_map = list1.Get(i)
        name  ="name" & i  'user_map.Get("name")
        country  = "country" & i 'user_map.Get("country")
        status = "status" & i  'user_map.Get("status")
        Spinner1.Add(name)
       
        str=str & $"${name}${CRLF}${country}${CRLF}${status}${CRLF}"$
   
    Next
    BBCodeView1.Text=    $"[Color=#ff0000][TextSize=17][Alignment=left][b]${str}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]"$
 

Attachments

  • testbbcodeloop.toby.zip
    10.1 KB · Views: 207
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
Thank you so much, in your own case, you have cut out database, what i want is to retrieve from mysql and not just string manipulation as shown here from your sample below. However, i tried to see if your idea will work if i integrate it into database as shown in the next code, but gave same result as my earlier complaint.

B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Public name, country, status As String
    Private Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("bblooptest2")
    TextEngine.Initialize(Activity)
    'BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\{}" & TAB & CRLF & Chr(13)
    BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    
    BBCodeView1.sv.ScrollViewOffsetY = 0
    
    'This adds button to bbcodeview
    Dim btn1 As Button
    btn1.Initialize("btn1")
    'btn2.Text = Chr(0xF04B) '"Play"
    #if B4i
    Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
    FontSize = 12
    #else
    btn1.Initialize("btn1")
    #End If
    Dim x As B4XView = btn1
    'x.Font =  xui.CreateFontAwesome(28)
    x.TextSize = 12
    x.Text = "View Answer" 'Chr(0xF04B)
    x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
    x.TextColor = Colors.DarkGray
    x.Color = Colors.LightGray
    'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
    x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)
    
    BBCodeView1.Views.Put("btn1", btn1)
    Dim list1 As List
    
    
    Dim str As String 
    For i = 0 To 3
        'We can now define map to hold each colum of our tables
        'Dim user_map As Map
        'user_map = list1.Get(i)
        name  ="name" & i  'user_map.Get("name")
        country  = "country" & i 'user_map.Get("country")
        status = "status" & i  'user_map.Get("status")
        Spinner1.Add(name)
        
        str=str & $"${name}${CRLF}${country}${CRLF}${status}"$
    
    Next
    BBCodeView1.Text=    $"[Color=#ff0000][TextSize=17][Alignment=left][b]${str}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]"$
    
    
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

This is how i tried to integrate your idea into mysql concept as shown below, but i ended up getting the same result i complained earlier:
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Public name, country, status As String
    Private Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("bblooptest2")
    TextEngine.Initialize(Activity)
    'BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\{}" & TAB & CRLF & Chr(13)
    BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    
    BBCodeView1.sv.ScrollViewOffsetY = 0
    
    'This adds button to bbcodeview
    Dim btn1 As Button
    btn1.Initialize("btn1")
    'btn2.Text = Chr(0xF04B) '"Play"
    #if B4i
    Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
    FontSize = 12
    #else
    btn1.Initialize("btn1")
    #End If
    Dim x As B4XView = btn1
    'x.Font =  xui.CreateFontAwesome(28)
    x.TextSize = 12
    x.Text = "View Answer" 'Chr(0xF04B)
    x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
    x.TextColor = Colors.DarkGray
    x.Color = Colors.LightGray
    'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
    x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)
    
    BBCodeView1.Views.Put("btn1", btn1)
    
    Dim jb As HttpJob
    jb.Initialize("sch2", Me)  'https://mftp.infinityfree.net
    jb.Download2("http://192.168.43.47/schphp.php", Array As String("action","sch2"))
    Wait For (jb) JobDone(jb As HttpJob)
    If jb.Success Then
            Dim parser As JSONParser
        parser.Initialize(jb.GetString)
    
        Select jb.jobname
    
            Case "sch2"
                
                'let list handle parser by declaring list
                Dim list1 As List
                list1.Initialize
                list1 = parser.NextArray 'json will extract data from json and store them as list
               
                If list1.Size = 0 Then
                    MsgboxAsync("not successful", "Not Successsful")
                Else
                    For i = 0 To list1.Size - 1
                        'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country")
                        status = user_map.Get("status")
                        Spinner1.Add(name)
                        Sleep(1500)
                    
                        Dim str As String
                        'For i = 0 To 3
                            'We can now define map to hold each colum of our tables
                            'Dim user_map As Map
                            'user_map = list1.Get(i)
                            name  = name  'user_map.Get("name")
                            country  = country 'user_map.Get("country")
                            status = status  'user_map.Get("status")
                            Spinner1.Add(name)
        
                            str=str & $"${name}${CRLF}${country}${CRLF}${status}"$
    
                        'Next
                        BBCodeView1.Text =    $"[Color=#ff0000][TextSize=17][Alignment=left][b]${str}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]"$
        
                    
                    
    '    BBCodeView1.Text = _
  ' $"[Color=#ff0000][TextSize=17][Alignment=left][b]${name}${CRLF}${country}${CRLF}${status}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]
  ' "$
 
                Next
                End If
                  
        End Select
        
    Else
        Log("Error!")
    End If
    jb.Release
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You are re’dimming the str variable within your loop. Don’t do that. Btw, concatenation is slow and memory intensive (strings are immutable) and if you have many records you may look at StringBuilder
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
You are re’dimming the str variable within your loop. Don’t do that. Btw, concatenation is slow and memory intensive (strings are immutable) and if you have many records you may look at StringBuilder
Thanks, Oliver, noted! But please, help me create time to look at #1. All the records are displaying well in many other views like b4xtable, spinner, but all records are displaying at a single spot in bbcodeview. Putting sleep(1500) as stated above indicates all records are displaying on a single spot. Please, do find time to help,Bros
Regards
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
Replace the for loop in your original code with the following code. It should work. If number of records is large, check out StringBuilder as mentioned by @OliverA .
B4X:
Dim str As String
                    For i = 0 To list1.Size - 1
                        'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country")
                        status = user_map.Get("status")
                        Spinner1.Add(name)
                    
                        str=str & $"${name}${CRLF}${country}${CRLF}${status}${CRLF}"$
                        
                    Next
                    BBCodeView1.Text=    $"[Color=#ff0000][TextSize=17][Alignment=left][b]${str}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]"$
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
In your first post, your setting the BBCodeView1.Text in the loop. Each time you set it, you set it the current record that you are processing in the loop, you are not adding. In post #5, you are dim'ming the str variable in the loop, so str = str & bla bla always means, take my freshly dim'ed string that contains nothing and add the current records information to it. Basically that once more does the same thing as your first post. Dim str outside of the loop! You should not need the sleep, especially with such a high value. The only time you may need a sleep if you are processing a ton of records and you want to give Android a break.

Ninja'd by @toby, who is nice enough to provide the code (yeah, I was just hinting: I have to leave some of the work to you @omo)
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
In your first post, your setting the BBCodeView1.Text in the loop. Each time you set it, you set it the current record that you are processing in the loop, you are not adding. In post #5, you are dim'ming the str variable in the loop, so str = str & bla bla always means, take my freshly dim'ed string that contains nothing and add the current records information to it. Basically that once more does the same thing as your first post. Dim str outside of the loop! You should not need the sleep, especially with such a high value. The only time you may need a sleep if you are processing a ton of records and you want to give Android a break.

Ninja'd by @toby, who is nice enough to provide the code (yeah, I was just hinting: I have to leave some of the work to you @omo)
Thank you, #5 was not really my code I was reporting issue based on response from Toby. My original post was where I referred you in #1. We were only trying to experiment things and giving feedback. Is never real life code someone will implement, it was only reporting based on experiment.

Nobody will implement sleep(1500) in live application, we were discussing something before we got to that stage. The large sleep(1500) was only for Toby to see that all records were displaying on top of each other. With small sleep, the display is fast, he may not see what I was pointing out.
Thank you for your submission, vital issues you raised are noted.
 
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
Replace the for loop in your original code with the following code. It should work. If number of records is large, check out StringBuilder as mentioned by @OliverA .
B4X:
Dim str As String
                    For i = 0 To list1.Size - 1
                        'We can now define map to hold each colum of our tables
                        Dim user_map As Map
                        user_map = list1.Get(i)
                        name  = user_map.Get("name")
                        country  = user_map.Get("country")
                        status = user_map.Get("status")
                        Spinner1.Add(name)
                    
                        str=str & $"${name}${CRLF}${country}${CRLF}${status}${CRLF}"$
                        
                    Next
                    BBCodeView1.Text=    $"[Color=#ff0000][TextSize=17][Alignment=left][b]${str}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]"$
Thank you so much, your approach worked except the button and sorry for delay I was trying to see how it will work out in my main project with more than 25 database columns before comming back here. There was no sleeping till the day break because two new cases came up. I finally found out the cause of one with large vertical spacing issues separating the records. I will raise new thread concerning that later. For the second issue, you did not put button under looping, what I wanted was for button to be created with each record, button ends each record. I tried to put button before next statement, but couldn't work out with the string. Please, if you get better idea how button will workout, please, let me know. You have done wonderful job, I appreciate
 
Upvote 0
Top