Android Question How to create an _ItemClick in a custome listview to click an Item

AndyChang

Member
Licensed User
Dear Sir
I use Panel to build a listview which has string and bitmap shown together as my attached png.
The way of coding to build the listview is just like my second png.
Could anyone can give me a simple sample and show me how to create the _ItemClick
Thanks a lot for your response.
Andy
 

Attachments

  • Screenshot.jpg
    248.2 KB · Views: 275
  • WayOfCoding.png
    53.2 KB · Views: 280

AndyChang

Member
Licensed User
Thanks Sir Manfred,
I have update the code to Label2.Initialize("Label2") and also fill all the other empty event_names.
But I still don't know how to establish a routine to get the item(position or index) when I click one of the many items.
Please help me.
Andy
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
lv.Initialize("lv")
lv_ItemClick is the click event I'm not at home to see how I do it
 
Upvote 0

AndyChang

Member
Licensed User
In my case, which View name should I use in the View_ItemClick. should I change the word View to Panel5 or scvorder or ...
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
It has 2 arguments I think #1 is the index and #2 is definitely Value as object
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
You can name it anything. I usually put in the name of the view

Dim tblShifts As Table
tblShifts.Initalise(me, "Shifts")

Sub Shifts_CellClicked(col As Int, row As Int)
End Sub
 
Last edited:
Upvote 0

AndyChang

Member
Licensed User
B4X:
Sub Creat_Insert_f1design_and_show
    GetTableinfo2
    Listview1.RemoveView
    Listview1.Initialize("ListView1")
    Listview1.SingleLineLayout.Label.TextSize=20
    Listview1.SingleLineLayout.Label.TextColor=Colors.White
    Listview1.Clear
    For i=0 To TablenameCount -1
        Listview1.AddSingleLine(Tablename(i))
    Next
    Activity.AddView(Listview1, 0%x, 48%y, 47%x, 43%y)
End Sub

As The above example, I create a Listview named Listview1 (all text no image data)
Then I use the way as below to get the ItemClick position(index). It works very well.
Now I need to add image data into the list. So I use Panel to Add the line as I post before. It work well. But I don't know how to apply the code below to the new application, so that I can get the ItemClick position(index)
I need help very much. I guess that it should be very similar to the code below.
B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
    ListView1_ItemClick_Select = True
    Dim recordID As Int
    Tablenm1 = Tablename(Position)
    Log("TableNow= "&Tablenm1)
    lblcommand.Text = "目前的設計檔案是 " & Tablenm1
    Log("fileProcessNow = "&fileProcessNow)
    TableNameNOW = Tablenm1
    If fileProcessNow = "Self" Then
        Cursor1 = SQL1.ExecQuery("SELECT itemno FROM " & Tablenm1 )
        Log("***  after cursor1 ****")
        For recordID = 0 To 9
            Cursor1.Position = recordID
            Itemno(recordID) = Cursor1.GetString("itemno")
            Log("Itemno= "&Itemno(recordID))
        Next
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Where are you getting the Value and doing something with it?
 
Upvote 0

AndyChang

Member
Licensed User
Dear Ricky
I create a set of sqlite databases which content a lot of nail art data. I want to create an APP to help nail art user to design their own nail art.
This is the last function that I need to write. Please help me. Thank you very much.
Andy
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
You'll need to zip up your code so we can look for you. We can't do it with just snippets
 
Upvote 0

AndyChang

Member
Licensed User
B4X:
You should use CustomListView. Everything will be simpler.

Dear Erel
I do need to learn CustomListView. But when I search the Key word [CustomListView] I find yourpost in 2012 7/15 (as below)
https://www.b4x.com/android/forum/t...xible-list-based-on-scrollview.19567/#content
B4X:
B4A Library CustomListView - A flexible list based on ScrollView
Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 15, 2012.

It is too complicated for me to use.
I found a CustomView item in Designer Add View list, but I think it is not the CustomListView
Is there any simple example which can teach me step by step about the most basic CustomListView include _ItemClick
Andy
 
Upvote 0

AndyChang

Member
Licensed User
Dear Ricky
My APP is a little bit large because of the database size. I have to cut down a lot before I transfer the code to you.
So I prefer to learn CustomerListView first (as Erel suggest). If I can have a simple example which can teach me step by step about the most basic CustomListView include _ItemClick then it will be very helpful to me to solve the problem.
Thank you Ricky
Andy
 
Upvote 0

AndyChang

Member
Licensed User
B4X:
Sub AddOrderitem(I As Int)
'    Initialize the Panel5
    Dim Panel5 As Panel
    Dim ImageView1 As ImageView
    Panel5.Initialize("Panel5")
    Panel5.Color=Colors.Black
    scvOrder.Panel.AddView(Panel5,0,PanelTop,100%x,PanelHeight)
   
'    build the ListView from the 1st part (series number)

    Dim Label2 As Label
    Label2.Initialize("Label2") : Label2.Color=Colors.Black : Label2.Tag="Label2" : Label2.TextSize = 16
    Label2.Text = I + 1
    Panel5.AddView(Label2,0,5dip,15dip,30dip)

'    Build the ItemNumber part
        
    Dim label1 As Label
    label1.Initialize("Label1") : label1.Color=Colors.Black : label1.Tag="Label1" : label1.TextSize = 16
    label1.Text = OrderItemNumber(I)
    Panel5.AddView(label1,70dip,5dip,120dip,30dip)

'    Build the image part

    ImageView1.Initialize("ImageView1")
    ImageView1.Gravity = Gravity.FILL
    Log("before  I="&I)
    ImageView1.SetBackgroundImage(OrderImage(I))
    Panel5.AddView(ImageView1,20dip,5dip,25dip,38dip)
    Log("after  I="&I)
'    再填 Spec   
    Dim label3 As Label
    label3.Initialize("label3") : label3.Color=Colors.Black : label3.Tag="label3" : label3.TextSize = 16
    label3.Text = OrderSpec(I)
    Panel5.AddView(label3,200dip,5dip,50dip,30dip)

'    Build the Qty part
        
    Dim label4 As Label
    label4.Initialize("label4") : label4.Color=Colors.Black : label4.Tag="label4" : label4.TextSize = 16
    label4.Text = OrderQty(I)
    Panel5.AddView(label4,260dip,5dip,20dip,30dip)

'    Build the UnitPrice  part

    Dim label5 As Label
    label5.Initialize("label5") : label5.Color=Colors.Black : label5.Tag="label5" : label5.TextSize = 16
    label5.Text = OrderUnitPrice(I)
    Panel5.AddView(label5,290dip,5dip,30dip,30dip)

'    Build the SubTTL part
        
    Dim label6 As Label
    label6.Initialize("label6") : label6.Color=Colors.Black : label6.Tag="label6" : label6.TextSize = 16
    label6.Text = OrderSubTTL(I)
    Panel5.AddView(label6,330dip,5dip,70dip,30dip)
   
    PanelTop=PanelTop+PanelHeight+1dip

End Sub
Each time when I call this Sub I create a new item list in my ListView. There may have several item list in the screan. Each item list is an item of order.
This is the way I create my ListView
Then I need to create an _ItemClick for user to choose one item in the ListView
How to write this Sub code (what is the listname XXX when I write the Sub XXX_ItemClick)
What is the following code necessary to write in the Sub, so that I can get the position(index) that the user click
Andy
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…