Android Question What is "view as android.view.view" ?

Watchkido1

Active Member
Licensed User
Longtime User
I tried to create a simple listview with b4xPages "Private ListView1 As B4XView".
Here ????
It was sooo much easier before with "ListView1.AddSingleLine2("Sunday", 1)".
Can someone please give me some examples?

a listview with:

Text1
Text2
Text3

How do I turn a panel into a view?
Why is it stuck with the xCustomlistview library?
It feels like "Don't use this!" is everywhere.
When I try to type "Activity..." it stays red in the IDE.
The examples from the forum somehow all do not work.

Thanks
 

Mahares

Expert
Licensed User
Longtime User
The examples from the forum somehow all do not work.
What examples in the forum don't work. You can easily create a project in B4Xpages using Listview. Nobody forces you to use xClv. Here is a complete example:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ListView1 As ListView
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
'    Root.LoadLayout("MainPage2")
    Root.LoadLayout("MainPage")  'has a listview
    For i = 0 To 10
        ListView1.AddTwoLines2("Lv line1 #" & i, "Lv line2 #" & i, i)
        Dim Label1 As Label
        Label1 = ListView1.TwoLinesLayout.Label
        Label1.TextSize = 25
        Label1.TextColor=xui.Color_Blue
    Next
End Sub
And if you want singleline2, here is the code:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")  'has a listview
    For i = 0 To 10
        ListView1.AddSingleLine2("Text " & i, i)
        Dim Label1 As Label
        Label1 = ListView1.SingleLineLayout.Label
        Label1.TextSize = 25
        Label1.TextColor = Colors.Blue
    Next
End Sub
I added the above also. You can if you want post your project to others to check it out

1687801539761.png
1687801354791.png
 
Last edited:
Upvote 0

Watchkido1

Active Member
Licensed User
Longtime User
Welche Beispiele im Forum funktionieren nicht. Mit Listview können Sie ganz einfach ein Projekt in B4Xpages erstellen. Niemand zwingt Sie, xClv zu verwenden. Hier ist ein vollständiges Beispiel:
B4X:
Sub Class_Globals
    Privates Root als B4XView
    Privates xui Als XUI
    Private ListView1 als ListView
End Sub

Öffentliches Sub initialisieren
End Sub

Private Sub B4XPage_Created (Root1 als B4XView)
    Wurzel = Wurzel1
' Root.LoadLayout("MainPage2")
    Root.LoadLayout("MainPage") 'hat eine Listenansicht
    Für i = 0 bis 10
        ListView1.AddTwoLines2("Lv line1 #" & i, "Lv line2 #" & i, i)
        Label1 als Label dimmen
        Label1 = ListView1.TwoLinesLayout.Label
        Label1.TextSize = 25
        Label1.TextColor=xui.Color_Blue
    Nächste
Sub
beenden
Und wenn Sie Singleline2 wollen, hier ist der Code:
B4X:
Private Sub B4XPage_Created (Root1 als B4XView)
    Wurzel = Wurzel1
    Root.LoadLayout("MainPage") 'hat eine Listenansicht
    Für i = 0 bis 10
        ListView1.AddSingleLine2("Text " & i, i)
        Label1 als Label dimmen
        Label1 = ListView1.SingleLineLayout.Label
        Label1.TextSize = 25
        Label1.TextColor = Colors.Blue
    Nächste
Sub
beenden
Ich habe das oben Gesagte auch hinzugefügt. Wenn Sie möchten, können Sie Ihr Projekt anderen zur Verfügung stellen, um es auszuprobieren

View attachment 143231View attachment 143230
you misunderstand me


Do not use list view https://www.b4x.com/android/forum/threads/6537/#content


Do not use the xcustomlistview code module https://www.b4x.com/android/forum/threads/84501/#content


However, the examples in the forum do not work with the customlistview library, only with the code module.
.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Please write in English. If I make a guess at what you are thinking, yes Erel does not recommend listview. He recommends xCustolistview. It is newer and much more versatile. He recommends not to use the customlistview class mode, but he wants you to use the xCustomlistview internal library if you want to use xcustomlistview instead of listview. If you decide to use customlistview or referred to as xCustomlistview, or sometimes just xClv, remove any customlistview class modules if you are using an old example . Simply, put a check in for xCustomlistview (1.73) in the library pane.
If you want to continue to use Listview, you can still use it. Many members still use it. It is not deprecated. All the newer B4A versions still support it.
 
Upvote 0

Watchkido1

Active Member
Licensed User
Longtime User
OK. I seem to express myself really badly. I'll try it again. when I use "Private ListView1 As B4XView" I am asked for "View as android.view.view" after the bracket at ListView. I can use a panel there at B4A or Activity. ... Activity doesn't work because it turns red and I'm having trouble with the panel. Can you give me examples of how that should look like? I can't find any examples in the forum. how to generate the string "text" on a label on a panel as "View as android.View.view"? What is "View as Android.view.view"?
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I am asked for "View as android.view.view" after the bracket at ListView
???? What do you mean?
Upload a small project showing the problem. I REALLY can´t follow.

Listview should not be used any longer. xCustomListview is the solution. Here you have full control. In Listview you have not.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
I seem to express myself really badly
Maybe not, but sometimes we see things clearly in our head and we thought the rest of people know what we're talking about.
The best way is upload a small project as DonManfred says.

The recommended way, is using a xCustomListView, you can still use AddTextItem.
You don't need to declare as B4XView, declare it as CustomListView.


when I use "Private ListView1 As B4XView"
Have you tried the Mahares sample? Please, test it. As you can see, it works, And he declares it this way: "Private ListView1 As ListView"
 
Last edited:
Upvote 0

Watchkido1

Active Member
Licensed User
Longtime User
Screenshot 2023-06-27 160332.png


B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    'Private lblHello As B4XView
    'Private ImageView1 As B4XView
    Private Page3 As B4XPage3
    Private EditText1 As EditText
    Private ListView1 As B4XView
    'Private Listview1 as CustomListView
    'Private Label As B4XView
End Sub

'You can add more parameters here.
Public Sub Initialize

End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Page2")
    Page3 = B4XPages.GetPage("Page 3")
    

   ' MENUE1
   ' MENUE2
End Sub

Sub MENUE1
    Dim lb As B4XView
    Dim MyLabel As Label
    MyLabel.Initialize("lb")
    lb = MyLabel
    lb.Text = "text1 "
    lb.As(Label).SingleLine=False
    ListView1.AddView(lb,0dip,0dip,100dip,20dip)
    
End Sub

Sub MENUE2
    Dim lb As B4XView
    lb.As(Label).Text = "text1"
    lb.As(Label).SingleLine=False
    ListView1.AddView(lb,0dip,0dip,100dip,20dip)
      
    Dim lb As B4XView
    lb.Text = "text2 "
    lb.As(Label).SingleLine=False
    ListView1.AddView(lb,0dip,0dip,100dip,20dip)
    
End Sub


Private Sub B4XPage_Appear
    'lblHello.Text = $"Hello ${B4XPages.MainPage.txtUser.Text}!"$
    UpdateImage
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub btnDraw_Click
    B4XPages.ShowPage("Page 2")
End Sub

Sub UpdateImage
    If Page3.Panel1.IsInitialized Then
        'ImageView1.SetBitmap(Page3.cvs.CreateBitmap)
    End If
End Sub

Sub btnSignOut_Click
    Page3.ClearImage
    UpdateImage
    B4XPages.ShowPageAndRemovePreviousPages("MainPage")   
End Sub


Private Sub EditText1_TextChanged (Old As String, New As String)
    
End Sub

Private Sub EditText1_EnterPressed
    
End Sub

Private Sub EditText1_FocusChanged (HasFocus As Boolean)
    
End Sub

Private Sub ListView1_ItemClick (Position As Int, Value As Object)
    Log(Position&" "&Value)
End Sub

Private Sub ListView1_ItemLongClick (Position As Int, Value As Object)
    
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Private ListView1 As B4XView
This is wrong !
You cannot set an Android ListView as a B4XView, it is not supported as a B4XView object.
You need to keep it as :
B4X:
Private ListView1 As ListView

Or switch to xCustomListView as already suggested.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I thought you do it with B4XView
The one time I know you can use listview as B4Xview is if you want to take a snapshop of the listview. Here is the code and it works:
B4X:
Dim x As B4XView= ListView1
    Dim b As Bitmap = x.Snapshot
    ImageView1.SetBitmap(b)
I spent a lot of time making those sample codes for you in post #2, but you don't seem to be appreciative, because you did not even bother testing them for yourself. I am glad it finally it took 11 posts for you to be convinced that it needs to be declared as Listview.
 
Upvote 0
Top