Android Question How can I Manage the Itemclick of the Customlistview created by map?

MroBurk

Member
Licensed User
Hi, I need help with this project. I created Clv1 in which the keys of map are showed, my need is to show in the Clv2 the values of the clicked key... How Can I manage the itemclick in Clv1? Could someone explain it to me, please?
 

Attachments

  • map.zip
    10.7 KB · Views: 187
Solution
I am not sure that I really understood what you are trying to achieve.
Check this.
As @Erel suggested you should start working using B4XPages and not the basic Activities.
Just consider that every Page that you can add using B4XPages correspond to an old extra Activity.
But without all the problems related to the Activity Life Cycle.
This example compile a CLV on the First Page with all the KEYS from the map.
Clicking an item will show the Second Page with another CLV where it will be added the relative VALUE of the map.

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why are you wasting your time with activities? There are all kinds of mistakes in your code related to the activities complex life cycle.

B4X:
Sub Button1_Click
    CustomListView1.Clear
    For Each KEY As Int In m.Keys
        CustomListView1.Add(CreateItem1(KEY), KEY)
    Next
End Sub

Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim ItemList As List = m.Get(Value)
    CustomListView2.Clear
    For Each item As String In ItemList
        CustomListView2.AddTextItem(item, "")
    Next
End Sub
 
Upvote 0

MroBurk

Member
Licensed User
Thanks Erel! I want to learn B4x, but there are no guides or tutorials for beginners to learn this .. I have seen all your tutorials and others and I want to tell you "thank you I learn a lot" ... There are mistakes because I spent hours and hours searching into the forum, and trying the code just to write for example a cycle to manage the item of a map in customlistview (exactly 17 hours and the code is not correct ..) .. Sometimes I am frustrated. .. but if it does what I need it is a success for me ... I want to understand why I have to use exactly this line of code .. I spend a lot of time learning this ... sorry I am not a professional programmer .. I am a doctor .. I only started 3 months ago ... If you have any other suggestions to improve me or start writing the correct code I am very grateful to you .. Thanks for everything ...
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I want to learn B4x, but there are no guides or tutorials for beginners to learn this ..
Starting from zero it can be harder in some ways because you have to discover everything, and it can be easier by other meaning because you have no other knowledge to overcome.
I really suggest you to spend time with the Booklets of @klaus.
They cover many many things with examples and explanations.
And of course every member it's here to help you by answering your questions.
Keep it up!
 
Upvote 0

MroBurk

Member
Licensed User
If I write the map in a file.txt, after map=File.ReadMap(..., File.txt) How Can I show the the values in CustomListView2 clicking on a key showed in customlistview1? In this case there is a string not a list!!!!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
In this case there is a string not a list!!!!
You cannot use File.ReadMap and File.WriteMap because your values are lists not strings. You have to use Serializator (need RandomAccessFile lib) to save the file and retrieve it.. See below code:
B4X:
' Write map to file
    Dim ser As B4XSerializator 'you need RandomAccessFile lbrary checked
    Dim typebytes() As Byte = ser.ConvertObjectToBytes(m)
    File.WriteBytes(File.DirInternal,"test.obj",typebytes)  'or what ever directory you are using to store the file

B4X:
  ' Read map from file
    Dim bytesread() As Byte = File.ReadBytes(File.DirInternal,"test.obj")
    m = ser.ConvertBytesToObject(bytesread)
 
Upvote 0

MroBurk

Member
Licensed User
the attached file is what I need... after the file.read, the values are a string not a list... @Mahares thanks I'll try... but I don't know How manage the value and the key in clv...

B4X:
Error occurred on line: 43 (aaa)
java.lang.RuntimeException: Method: getSize not found in: java.lang.String
    at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:985)
    at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:644)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:731)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.aaa.afterFirstLayout(aaa.java:105)
    at b4a.example.aaa.access$000(aaa.java:17)
    at b4a.example.aaa$WaitForLayout.run(aaa.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
 

Attachments

  • map1.zip
    13.3 KB · Views: 166
  • map1.PNG
    map1.PNG
    47.5 KB · Views: 179
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I am not sure that I really understood what you are trying to achieve.
Check this.
As @Erel suggested you should start working using B4XPages and not the basic Activities.
Just consider that every Page that you can add using B4XPages correspond to an old extra Activity.
But without all the problems related to the Activity Life Cycle.
This example compile a CLV on the First Page with all the KEYS from the map.
Clicking an item will show the Second Page with another CLV where it will be added the relative VALUE of the map.
 

Attachments

  • MapCLV-Sagenut.zip
    16.7 KB · Views: 173
Upvote 1
Solution

Sagenut

Expert
Licensed User
Longtime User
Remember that it's very important to try to understand the code that you receive/found.
The worst thing that anyone can do is to just Copy & Paste working code without understanding what is going on.
 
Last edited:
Upvote 0

MroBurk

Member
Licensed User
thanks @Sagenut, this is what I want to do (I need to understanding what the code what is going on... ). Dear @Erel I'm wasting my time with activities because the tutorials are done with them... I'll try to do my work with b4xpages for the future... thanks to all
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
thanks @Sagenut, this is what I want to do
@MroBurk
Your original project you posted in post #1 was dealing with map holding 3 lists and in post #9, the project is totally different as it deals with all strings in the map. You really shouldn't make a 180 degree turn and switch topics in the middle of a thread because it makes it hard to help you. The same thing for saving and reading maps which you were at some point interested in. The project in post 9 did not address that topic.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Valid point. We are in a transition period.
Just yesterday I was thinking of creating video tutorials, especially in Italian, before checking if those published by Erel were only on Vimeo and not on YouTube.
Having seen that they are also on YouTube, I gave up, as on this platform it is possible to activate subtitles in any language generated automatically (however imperfect, they will certainly be sufficient to understand everything).

If that unique Erel's video tutorial about B4XPages wasn't enough, I could do others. It all depends on the likes that this post will receive (and a little also on any donations ?).

P.S.
You can vote here:
https://www.b4x.com/android/forum/threads/b4xpages-video-tutorials.138812/post-878848
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Just yesterday I was thinking of creating video tutorials, especially in Italian, before checking if those published by Erel were only on Vimeo and not on YouTube.
Having seen that they are also on YouTube, I gave up, as on this platform it is possible to activate subtitles in any language generated automatically (however imperfect, they will certainly be sufficient to understand everything).

If that unique Erel's video tutorial about B4XPages wasn't enough, I could do others. It all depends on the likes that this post will receive (and a little also on any donations ?).
https://www.b4x.com/android/forum/threads/b4xpages-video-tutorials.138811/post-878845
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
@MroBurk
Your original project you posted in post #1 was dealing with map holding 3 lists and in post #9, the project is totally different as it deals with all strings in the map. You really shouldn't make a 180 degree turn and switch topics in the middle of a thread because it makes it hard to help you. The same thing for saving and reading maps which you were at some point interested in. The project in post 9 did not address that topic.
My fault.
I didn't checked the original project and just relied on the description of the question.
I will remove my post if it can be considered source of misunderstanding.
 
Upvote 0
Top