CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

xor83

Member
Licensed User
Longtime User
Thanks Erel it worked ...:icon_clap:

"1. There is no CheckBox in your list item layout."

Actually I meant there are some controls in layout...

One day I will come to Israel and hug you...:sign0188:
 

Inman

Well-Known Member
Licensed User
Longtime User
Will it be possible to change the color of selected list view item from orange to blue that is used by the holo theme of Android 3+?

I understand that idPressed = r.GetStaticField("android.R$drawable", "list_selector_background") is the one that needs to be modified. Apparently list_selector_background is used by Android 2.3 and below, while Android 3+ uses list_selector_holo_dark, according to this post

android - Default selector background in Clickable Views - Stack Overflow

I changed to that value but it returns an error, probably because it is not public. Any way to acheive this?
 

Informatix

Expert
Licensed User
Longtime User
Will it be possible to change the color of selected list view item from orange to blue that is used by the holo theme of Android 3+?

I understand that idPressed = r.GetStaticField("android.R$drawable", "list_selector_background") is the one that needs to be modified. Apparently list_selector_background is used by Android 2.3 and below, while Android 3+ uses list_selector_holo_dark, according to this post

android - Default selector background in Clickable Views - Stack Overflow

The system drawable to use is "list_pressed_holo_dark".
 

Inman

Well-Known Member
Licensed User
Longtime User
Thanks man. While that didn't work simply by replacing the drawable's name in the class's code, I was able to get it work with AndroidResources library and now I get the correct holo blue color.
 

electronik54

Member
Licensed User
Longtime User
how to change itemclick color

:sign0085:
how to change itemclick color in this kind of list. can the itemclick be disabled but text still remains?

and how do i fix this
SC20130404_170733.png

my panel in background of listview is white color. there is nothing of that color in layout or in the code

here is the code
B4X:
FACLV1.Initialize(Me, "FACLV1")
   FACLV2.Initialize(Me, "FACLV2")
   FA_SV_pnl.AddView(FACLV1.AsView, 0, 0, FA_SV_pnl.Width, FA_SV_pnl.Height)
   FA_sv_detail_pnl.AddView(FACLV2.AsView, 0, 0, FA_sv_detail_pnl.Width, FA_sv_detail_pnl.Height)
   FACLV1.DefaultTextBackgroundColor = Colors.White
   FACLV1.DefaultTextSize=13
   FACLV1.DefaultTextColor=Colors.Black
   FACLV2.DefaultTextBackgroundColor = Colors.White
   FACLV2.DefaultTextSize=13
   FACLV2.DefaultTextColor=Colors.Black
   If info="" Then
   FACLV1.AddTextItem(""&Cursor7.GetString("Treatment"), "a")
   Else
   FACLV1.AddTextItem(""&Cursor7.GetString("Treatment"), "a")
   FACLV2.AddTextItem(""&Cursor7.GetString("Information"), "a")
 
Last edited:

socialnetis

Active Member
Licensed User
Longtime User
Does this CustomListView recycles the memory?
I mean if you have 1000 items, and you are seeing items 1-9, and you scroll a little to see 2-10, the item number 1 will be recycle?
 

roarnold

Active Member
Licensed User
Longtime User
CustomListView

I installed it in my program and received the first error "Panel must be initialized" then the second error is "Object = Null"

I am a bit confused.

Thanks,
R
:BangHead:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
how to change itemclick color in this kind of list. can the itemclick be disabled but text still remains?
This is the code that sets the selection panel:
B4X:
Public Sub InsertAt(Index As Int, Pnl As Panel, ItemHeight As Int, Value As Object)
    
   Dim sd As StateListDrawable
    sd.Initialize
    sd.AddState(sd.State_Pressed, pressedDrawable)
    sd.AddCatchAllState(Pnl.Background)
You can modify it and remove the pressed state for the items that should not be "clickable".

Does this CustomListView recycles the memory?
Unlike the standard ListView (or Table class) all the items are created when the list is built. The advantage is that it is much easier to customize the list items. See the first post for more details.

@roarnold please start a new thread for your question and include your code.
 

GMan

Well-Known Member
Licensed User
Longtime User
After trying some things out i still cant place an image in the CustomListView.

Here's my code so far:
B4X:
   Dim clv4 As CustomListView
   clv4.Initialize(Me, "clv4")
   SpeciesPanel.AddView(clv4.AsView, 0, 0, SpeciesPanel.Width, SpeciesPanel.Height)
   clv4.DefaultTextBackgroundColor = Colors.Black
   clv4.AddTextItem(File.GetText(File.DirInternal,"SPECS1.grl"),0)

This works fine, the loaded textfile is displayed.

But after adding
B4X:
clv4.InsertAt( 0, SpeciesPanel, SpeciesPanel.Height ,"SPECSpic1.png")

it causes an error that the parent already has a child.

:sign0085:
 

klaus

Expert
Licensed User
Longtime User
The problem is the following:
- You have a Panel called SpeciesPanel.
- You add the CustomListView clv4 onto this panel.
- Then you try to add the CustomListView's parent panel onto the CustomListView as a child View, this for sure won't work.
You should add a Panel with the image or a panele with an ImageView on it.

Best regards.
 

GMan

Well-Known Member
Licensed User
Longtime User
OK, i got that now - but still confused.
I looked for something like

B4X:
clv4.AddImageItem.....

or something similar, but dont found it.

So i am still not able to add the picture to the scrollable clv4 :sign0104:

The textpart works fine and i can add several of contents/file contents to them, but (s.a.)
 

GMan

Well-Known Member
Licensed User
Longtime User
Grüetzi Klaus,

Danke, das hat mir geholfen :cool:

Nun ist ja in der ListView jedes "item" klickbar - lässt sich das (also das wechseln der Hintergrundfarbe beim Berühren) ausschalten ?
---
Thx, that helps me :cool:

As in the ListView each "item" is cklickable - is their the possibilty to switch that off (i mean the changing of the backcolor when touching).

Pfüeti
 

klaus

Expert
Licensed User
Longtime User
As in the ListView each "item" is cklickable - is their the possibilty to switch that off
Yes, but it needs a modification of the CustoListView class.
The attached program does it.
Look at lines 109 to 113 in the class.
This line
' sd.AddState(sd.State_Pressed, pressedDrawable)
is replaced by
Dim cdw As ColorDrawable
cdw = Pnl.Background
sd.AddState(sd.State_Pressed, cdw)


Best regards.
 

Attachments

  • TextPlusImage1.zip
    36.8 KB · Views: 390

GMan

Well-Known Member
Licensed User
Longtime User
But this affects the complete class for the complete app...so this modification supresss that function also then when i want it.

Can i derive a seperat class from this, if needed ?
 

klaus

Expert
Licensed User
Longtime User
But this affects the complete class for the complete app...so this modification supresss that function also then when i want it.
You didn't explain that in your question.

To add this function you need to add a boolean variable in these routines to define if you want the item selectable or not:
AddView
AddTextItem
InsertAt
InsertAtTextItem

and modify lines 109 to 112 where you check the Selectable variable and set the selected background to either
sd.AddState(sd.State_Pressed, pressedDrawable)
or
sd.AddState(sd.State_Pressed, cdw)

Can I derive a separate class?
Yes, the class in my previous post is already a 'special' class.

Best regards.
 

GMan

Well-Known Member
Licensed User
Longtime User
Thx a lot - this will work fine and i learned a lot again ;)
 

gawie007

Member
Licensed User
Longtime User
Raising an event in a Class

I was trying to get my head around how this works and "borrowed" some of Erel's code in the CustomListView.
I have broken this down to quite a simple bit of code so that it should be easier for people to follow (including me!).

The App has a Label and a ToggleButton.
The user clicks the ToggleButton to change the state of an instance variable in the Class.
When this variable is changed in the methods, it raises an Event in the Main code module which in turn displays what was sent from the event in a label.

I am not sure if this will be helpful but it cleared it up for me! There are also perhaps better ways to do this.

Kind regards

Gavin

B4X:
'Main Activity Module
Sub Process_Globals
   Dim RE1 As RaiseEvent
End Sub

Sub Globals
   Dim Label1 As Label
   Dim ToggleButton1 As ToggleButton
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main")
   RE1.Initialize(Me,"RE1")
End Sub

Sub ToggleButton1_CheckedChange(Checked As Boolean)
   'Press ToggleButton to change the Fire Class Instance Variable
   If Checked Then
      RE1.SetFire(True)
   Else
      RE1.SetFire(False)
   End If
End Sub

Sub RE1_FireEvent(FiringStatus As String)
   'This Event is raised every time the ToggleButton is changed
   Log("Firing Status: " & FiringStatus)
   Label1.Text = "Firing Status: " & FiringStatus
End Sub

The RaiseEvent Class:

B4X:
'Class module: RaiseEvent
Sub Class_Globals
   'Class Instance variables
   Private EventName As String
   Private CallBack As Object
   Private Fire As Boolean
   Private FireText As String
End Sub

Public Sub Initialize(vCallBack As Object, vEventName As String)
   'Initialise the Class Objects
   EventName = vEventName
   CallBack = vCallBack
   Fire = False
   FireText = "None"
End Sub

Public Sub SetFire(vFire As Boolean)
   'Class Method
   Fire = vFire
   If Fire = True Then
      FireText = "Did Fire"
   Else
      FireText = "Did Not Fire"
   End If
   
   FireTest   'Call the method that raises an Event
End Sub

Private Sub FireTest
   'Class Method to Raise an Event
   If SubExists(CallBack, EventName & "_FireEvent") Then
      CallSub2(CallBack, EventName & "_FireEvent", FireText)
   End If
End Sub

I have attached the code should anyone want to use it.
 

Attachments

  • ClassTest.zip
    7.6 KB · Views: 344
Last edited:
Status
Not open for further replies.
Top