Android Question Button in a CustomListView

MroBurk

Member
Licensed User
Dear Gentleman, I need Help with 2 problems:
I'd like to understand:
1) How can I declare"For i=0 to infinite" or" i=0 to number of row in a file *.txt"?
2°) How can the code (posted below) works for each row that I create in a customlistview (by "file.txt")? I attached the example's file. I'm blocked... Specifically, I need to understand How can I use "btnsender" with each row? because in this case the btnsender (as string) is the same for each row (the last "stringarray").


thanks for your help...

Lunch Youtube with string:
Private intento As Intent
    intento.Initialize(intento.ACTION_VIEW,btnsender)
    intento.SetComponent("com.google.android.youtube/.UrlActivity")
    StartActivity(intento)
end sub
 

Attachments

  • customAnswer.zip
    12.2 KB · Views: 88

Sagenut

Expert
Licensed User
Longtime User
Check this.
I didn't put too many comments, sorry.
I will be happy to answer your questions (even on the Italian section if you want).
I stripped away some parts.
Answers to your questions are included into the code.
 

Attachments

  • customAnswer-Sagenut.zip
    12.2 KB · Views: 92
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Feel free to ask whatever it's not clear.
In this case:
1) How can I declare"For i=0 to infinite" or" i=0 to number of row in a file *.txt"?
You use a List.
To obtain the quantity of items contained in a List you need
B4X:
List.Size
The numeration of items go from 0 to X, so we need
B4X:
List.Size - 1
to point to the last item starting from 0.

2°) How can the code (posted below) works for each row that I create in a customlistview (by "file.txt")?
In the Button_Click Sub you need to set a new button and assign the Sender to it.
This will not create a Copy of the Button but will create a Reference to the clicked one (Sender).
Now everything you will read or write on the Reference Button will correspond/happen to the Sender one.
This logic work in the same way for every view that you can click in the CustomListView.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Nice going @Sagenut. Another easy way is:
You make the CLV return value as: stringarray(1) as shown below:
B4X:
CustomListView1.Add(CreateItem2(stringarray(0), stringarray(1),CustomListView1.AsView.Width, 60dip),stringarray(1))
Then you use the Customlistview1 item click as shown below without having to click any buttons . The button tags and the button1 code will not be needed.
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim intento As Intent
    intento.Initialize(intento.ACTION_VIEW, Value)
    intento.SetComponent("com.google.android.youtube/.UrlActivity")
    StartActivity(intento)
End Sub
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I didn't want to totally transform his code because maybe it was a path to something else.
But your addition it's helpful as well.
 
Upvote 0
Top