Android Question listview sqlite help

apty

Active Member
Licensed User
Longtime User
I have a listview that reads data from sqlite database. I would like to achieve the following:
Once i click on an item in the listview, it should take me to details of the item (i.e another activity that has textviews showing each field etc). Basically, i have an activity that shows all fields in a given record and i want it to display once i click on the record in the listview..Please help
 

eps

Expert
Licensed User
Longtime User
It is possible..

something like this, of course you will have to have opened up the DB etc first..

Use the '2' versions of ListView and set the tag of the listview item to the id of the record and then use this to retrieve the information you are interested in, in your click event

B4X:
    Cursor = SQL1.ExecQuery("SELECT _id, name, enddate, display_date FROM event order by startdate,enddate")

  
    For i=0 To Cursor.RowCount-1

        Cursor.Position=i



          ListView1.AddTwoLinesAndBitmap2(Cursor.GetString("name"), Cursor.GetString("display_date"), Null, Cursor.GetInt("_id"))

  
    Next

    Cursor.Close

and

B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)

'do some processing using the Value

End Sub
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
i could now load the data from sqlite to listview. However, i am still unable to pass the data on listview item click to another activity with a different layout (i.e details page)..please help
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Please show us some code! It's like trying to read a book in the dark!!!

1) Are you using AddSingleLineListView2 or similar with the 2 at the end to set a hidden value on the ListView item?

2) Set this to the id of the record you are interested in seeing more about.

3) On the Click event of the ListView you then pass this value into it.

4) Re-Read the record using the Value and retrieve more information about the record.

5) Then display, use MsgBox or similar initially to display the information.

Job Done.

Which steps have you done from above and can you post some code indicating each one.
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
i have the following in main activity
B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
    StartActivity("viewitems")

  

End Sub

and the following in viewitems activity
B4X:
CallSubDelayed(Main, "ListView1_ItemClick")

how can i pass the value result from main activity to viewitems activity?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Store the value in a process_global variable. In activity viewitems you then can read the global variable...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need an example on how to create a process global variable and how to read that variable on other place? REALLY? Did you read the documentation? Did you searched for an solution about this?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim globalvariable As Object
End Sub
Sub ListView1_ItemClick (Position AsInt, Value AsObject)
  globalvariable = Value  
  StartActivity(viewitems)
End Sub

and in Activity viewitems then
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Activity.LoadLayout("main")
    End If
  Dim value AS Object = Main.globalvariable
END SUB
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
there's a slight challenge though, how can i use the passed value (in activity viewitems) to autofill edittexts with database values? e.g. if i have passed a value x in textview1, and i have textview2 and textview3, how can i aoutofill textview2 and textview3 based on the passed value?
 
Upvote 0
Top