Android Question change the values of list

Mehrzad238

Member
I already know that with this line we can change the values of list:
B4X:
List.Set(Index, item)
let's say I have a few data that I have added by using Type, one of this type is a list of 0 that one of them is 1, which means that 1 is the chosen one, so I have made a changed one of this zeros to 1 and now I have two 1 in this type which it must be one of them, my question is how can I have only 1 on this type and not two or more?

for changing values I am using a series of checkbox/ radio button by using this link:

https://www.b4x.com/android/forum/threads/check-only-one-checkbox.106342/post-665665
 
Solution
Well I found the solution:

B4X:
Sub def_CheckedChange(Checked As Boolean)
    Dim c As CheckBox= Sender
    If c.Tag <> Null Then
        Dim arrayeh() = c.Tag As Object
        Dim Position = arrayeh(0) As Int
'        Dim boss = arrayeh(1) As Int
        Dim item = List.Get(Position) As office
        If Checked Then
            For Each box As CheckBox In boxes.Values
                If box <> c Then
                    box.Checked = False
                End If
            Next
            item.boss=1                    ' here we make new boss
            List.Set(Position,item)  'Here updates office type for new changes
        Else if Checked = False Then  'Here is the solution 
            item.boss=0                ' here we...

Mehrzad238

Member
I have a few issues with this. help me to fix that
and if there is a better way please show me and I will follow your lead
 

Attachments

  • checkboxes.zip
    9.2 KB · Views: 92
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have downloaded your project and I have run it. It looks to me that it is working well. If you check a checkbox then it becomes checked and any previously checked box becomes unchecked. I imagine that this is what you want to do.

I would make a couple of comments, but they are not very important. Firstly, you probably know that if you use radio buttons then checking one will automatically uncheck all the others (in the same panel/view) without you needing to do anything. But if you want to allow all items to be unchecked (as your example does allow) then you need checkboxes. Secondly, I would use a List rather than a Map; in your example the map functionality is not used.

I think the Erel was just commenting that List.Set is not a common usage, not that there was anything wrong with it. You are not using List.Set in your example anyway, so why worry.
 
Upvote 0

Mehrzad238

Member
You are not using List. Set in your example anyway
@Brian Dean Are you sure that I'm not using List. Set in my example?
let me show you where:
B4X:
itemlist.Set(Position,item)

this line code updates Type humans for this change item.boss=1

And most important things the subject of this thread is

change the values of list

not this:
It looks to me that it is working well. If you check a checkbox then it becomes checked and any previously checked box becomes unchecked. I imagine that this is what you want to do


you probably know that if you use radio buttons then checking one will automatically uncheck all the others (in the same panel/view) without you needing to do anything

I know this but I just want it to use checkbox


I would use a List rather than a Map; in your example the map functionality is not used

the boxes map is was for this example:
https://www.b4x.com/android/forum/threads/check-only-one-checkbox.106342/post-665665

and because of that only one check box will check and you have only one choice to make

if look take look at the log I put in my example is very clear what is happening and where is going wrong and needed to be fixed.

now if you have understood what I need to do, help me.
if you didn't don't change the subject of this thread
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
There has been a mix-up somewhere, @Mehrzad238 . The project that you attached in post #4 (checkboxes.zip) is the example that you mention from the forum, with an additional Log statement that I assume you have added. It does not contain the line "itemlist.Set(Position,item)".

I cannot find your own project in any of the posts, but I will be happy to look at it if you wish.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
    Dim lst As List
    lst.Initialize
    For i = 0 To 9
        lst.Add(i)
    Next
    logList(lst)
  
    lst.Set(2, 123)
    logList(lst)
  
  
  
Private Sub logList(lst As List)
    For Each v As Object In lst
        Log(v)
    Next
    Log("---------")
End Sub


0
1
2
3
4
5
6
7
8
9
---------
0
1
123
3
4
5
6
7
8
9
---------
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
And most important things the subject of this thread is

change the values of list
Please UPLOAD a small project which SHOWS the problem.

We can not help you if you hide all relevant code from us. Help us helping you.

Even if rarely used i expect the command mylist.Set to work.
 
Last edited:
Upvote 0

Mehrzad238

Member

Attachments

  • List Example.zip
    190.3 KB · Views: 92
Upvote 0

Mehrzad238

Member
Well I found the solution:

B4X:
Sub def_CheckedChange(Checked As Boolean)
    Dim c As CheckBox= Sender
    If c.Tag <> Null Then
        Dim arrayeh() = c.Tag As Object
        Dim Position = arrayeh(0) As Int
'        Dim boss = arrayeh(1) As Int
        Dim item = List.Get(Position) As office
        If Checked Then
            For Each box As CheckBox In boxes.Values
                If box <> c Then
                    box.Checked = False
                End If
            Next
            item.boss=1                    ' here we make new boss
            List.Set(Position,item)  'Here updates office type for new changes
        Else if Checked = False Then  'Here is the solution 
            item.boss=0                ' here we make new boss
            List.Set(Position,item)  'Here updates office type for new changes
        End If
    End If
End Sub
 
Upvote 0
Solution

Mahares

Expert
Licensed User
Longtime User
now if you have understood what I need to do, help me.
Dude, the project you posted in post #4 has nothing to do with list. It is about map and checkboxes. Brian is correct. Instead of getting upset and blowing your top, you should apologize. Check it for yourself.
 
Upvote 0

Mehrzad238

Member
Hi, I just wanted to apologize to everyone that has been trying to help me with my problem and be grateful for all thing you have been done to me specifically @Brian Dean, you are was the first one who responds to me
 
Upvote 0
Top