[NOOB] Listview doesn't get focus..?

Widiar

Member
Licensed User
Longtime User
Listview doesn't get focus..? [SOLVED]

Hello everyone. I'm pretty new with this thing, thou I've done my share with VB and VB.NET in my younger years.

I tried to do a small program that uses custom listview2 object (from a library) for richtext/string support.

My program worked just fine when I used normal listview, but as I had to add the listview2 element(s) by code, I cannot get the object to get any touch or click events no matter how I try.

Currently I have this snip of code in my activity sub:

B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime=True Then ' Load only if first load

SetupData.Initialize
Phrases.Initialize
Phrases2.Initialize
PhraseGroup.Initialize
   
' *************** Initialize Main Screen **************************
PnlMain.initialize("")
PnlMain.Visible=True
Activity.AddView(PnlMain, 0, 0, 100%x, 100%y)
PnlMain.LoadLayout("Main") ' Load the Mainscreen layout

and this later on in the same sub:

B4X:
' ********************** Initialize Listview elements *****************************

   ListTitles.Initialize("") ' First listview element
   ListPhrases.Initialize("") ' Second listview element
   ListSearch.Initialize("") ' 3rd
   ListNames.Initialize("") ' 4th   
' ********************** Add Listview elements tp pnlMain *****************************
   PnlMain.AddView(ListTitles,2%x,12%y,98%x,70%y)
'   Activity.AddView(ListTitles,2%x,12%y,98%x,70%y) ' Shows, but does not get focus either?
   PnlMain.AddView(ListPhrases,2%x,12%y,98%x,70%y)
   PnlMain.AddView(ListSearch,2%x,12%y,98%x,70%y)
   PnlMain.AddView(ListNames,2%x,12%y,98%x,70%y)         
    
End If ' End of is it a first time load if

In my "Main" layout I only have some buttons which control the information added to the listview elements. They work fine and get the focus and click events normally.

I have tried to add the listview2 elements to activity instead of pnlmain, but the result is the same. They will show up, but don't interract (trigger click events nor touch/scroll).

I've been trying to solve this for 3 hours now while reading the tutorials and documents and forum, no luck.

Any help would be greatly appreciated.

(All the listview elements are declared in the "sub globals")
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
If FirstTime=True Then ' Load only if first load
This is an error! You should always load the layout when the activity is created. Not just when the process first starts.

See the activities and process lifecycle tutorial.


About the event. You are setting the EventName parameter to "". This means that no sub will handle the event.
 
Upvote 0

Widiar

Member
Licensed User
Longtime User
Been working with this 2 more hours with no success, any help? As soon as I try to create the listview elements by code (be them standard listview or listview2 from the external library) they quit working like they're not part of the parent element (either activity or mainpanel?) and don't get any events.

I'll attach the full code here, in case someone has the energy and time to look it out.

- Wid
 

Attachments

  • Wid-Test1.zip
    10 KB · Views: 134
Upvote 0

Widiar

Member
Licensed User
Longtime User
This is an error! You should always load the layout when the activity is created. Not just when the process first starts.

See the activities and process lifecycle tutorial.


About the event. You are setting the EventName parameter to "". This means that no sub will handle the event.

Thank you for your reply. I shall check again the lifecycle tutorial. Still not quite sure what to put in the eventname in this case, I kind of assumed the activity will take care of it when the mainpanel is loaded into it. Obviously that is not the case.
 
Upvote 0

Widiar

Member
Licensed User
Longtime User
Changed the event names to be the same as the element name so that the clicks would handle them, but no luck still.

I also moved the adding of listview elements part out from the "load only when first time" condition but the listview elements still don't seem to fire (buttons from the designer layout works just fine.)


I insert the latest code in here too, but here are the (in my opinion) relevant parts from the code.

In the sub globals I have stated:

B4X:
ListPhrases.Initialize("ListPhrases")
ListSearch.Initialize("ListSearch")
ListNames.Initialize("ListNames")
ListTitles.Initialize("ListTitles")
ListSub.Initialize("ListSub")

Which are the name of the listview-elements I'm using. For the event name I used the name of the listview element, as there are now events like
B4X:
ListTitles_ItemLongClick (Position As Int, Value As Object)
in the code. Hopefully this is correct?

In the activity sub I have this:

B4X:
' *************** Initialize Main Screen **************************
PnlMain.Initialize("")
Activity.AddView(PnlMain, 0, 0, 100%x, 100%y)
PnlMain.LoadLayout("Main") ' Load the Mainscreen layout      
' **************** Main screen initialized *************************

And in the main layout made in the designer, I have just a few buttons which works just fine as stated earlier.

In the end of the activity process I add the listview elements into the main panel like this:

B4X:
' ********************** Add Listview elements tp pnlMain *******************
   PnlMain.AddView(ListTitles,2%x,12%y,98%x,70%y)
'   Activity.AddView(ListTitles,2%x,12%y,98%x,70%y) ' Shows, but does not get focus either?
   PnlMain.AddView(ListPhrases,2%x,12%y,98%x,70%y)
   PnlMain.AddView(ListSearch,2%x,12%y,98%x,70%y)
   PnlMain.AddView(ListNames,2%x,12%y,98%x,70%y)         
 ' ********************** Main layout loaded? *******************************

I did re-read the activity/lifecycles tutorial but obviously I'm missing something very obvious and silly here, as all my programs made with designer (only) works flawlessly...
 

Attachments

  • Wid-Test1.zip
    10 KB · Views: 146
Last edited:
Upvote 0

Widiar

Member
Licensed User
Longtime User
Moved .initialize -codes to activity as suggested by Erel, but still can't get any element to trigger.

Running out of ideas, so here is the latest code for someone to look.

- Wid
 

Attachments

  • Wid-Test1.zip
    10 KB · Views: 128
Upvote 0

klaus

Expert
Licensed User
Longtime User
In this code you add other ListViews on top of ListTitles
B4X:
PnlMain.AddView(ListTitles,2%x,12%y,98%x,70%y)
'        Activity.AddView(ListTitles,2%x,12%y,98%x,70%y) ' Shows, but does not get focus either?
PnlMain.AddView(ListPhrases,2%x,12%y,98%x,70%y)
PnlMain.AddView(ListSearch,2%x,12%y,98%x,70%y)
PnlMain.AddView(ListNames,2%x,12%y,98%x,70%y)
these ListViews are transparent but consume the events.
You should either invert the adding order or add Visible = False for the last three.

Best regards.
 
Upvote 0

Widiar

Member
Licensed User
Longtime User
In this code you add other ListViews on top of ListTitles
B4X:
PnlMain.AddView(ListTitles,2%x,12%y,98%x,70%y)
'        Activity.AddView(ListTitles,2%x,12%y,98%x,70%y) ' Shows, but does not get focus either?
PnlMain.AddView(ListPhrases,2%x,12%y,98%x,70%y)
PnlMain.AddView(ListSearch,2%x,12%y,98%x,70%y)
PnlMain.AddView(ListNames,2%x,12%y,98%x,70%y)
these ListViews are transparent but consume the events.
You should either invert the adding order or add Visible = False for the last three.

Best regards.



Oh my God.. 5 hours for such a silly mistake :D .. thank you Klaus so much for the help, would have taken me 5 (or 50) more hours to realize where the focus went. :sign0098: (And thanks for solving the other issues, Erel!)
 
Upvote 0
Top