Android Example Get all views or values of a CustomListView item

I developed a simple example about how I think you should handle easily views and values of a CustomListView item.

3 things:

1) constants pointing to the views order in the item;
2) two custom types, one for the views and the other for the values;
3) four functions (you can find them in a Region named "GET CLV ITEM STUFF"):
[EDIT] Now they are two functions only, version 2.

B4X:
' Returns views of item at the given item index.
Sub GetItemViewsByIndex(ItemIndex As Int) As tItemViews 'ignore

B4X:
' Returns views of item that contains the given View.
' USES: function GetItemViewsByIndex
Sub GetItemViewsByView(Vw As View) As tItemViews 'ignore

B4X:
' Returns values of item at the given item index.
' USES: function GetItemViewsByIndex
Sub GetItemValuesByIndex(ItemIndex As Int) As tItemValues 'ignore

B4X:
' Returns values of item that contains the given view.
' USES: function GetItemValuesByIndex
Sub GetItemValuesByView(Vw As View) As tItemValues 'ignore


The test is not so smart, but it's about 4:00 AM, don't expect too much :D:

1) check / uncheck the Sold checkbox.
The item values will be get by view (the checkbox) and shown (ToastMessageShow and log);

2) set focus on some Description EditText.
Here the views will be get two times:
first time by view (you will see change the beer and the Code text);
second time, after 1.5 sec., by index (cancel previous changes)


I hope you like it.

Maybe I'll look for a way to make this more generic.


Tips to improve this thing will be very welcome.


[NOTE: I added GetDividerHeight to the CustomListView]


Attached Version 2: see my posts #2 and #3.
 

Attachments

  • Handle CustomListView.zip
    98.3 KB · Views: 680
  • Handle CustomListView 2.zip
    98.6 KB · Views: 749
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Tips to improve this thing will be very welcome.
My own tip :confused:

I could need two only functions; the parameter could be of type object and I could check it:
B4X:
' Returns item's views
Sub GetItemViews(IndexOrView As Object) As tItemViews 'ignore
  If IndexOrView Is View Then
     ' ...
   Else If IndexOrView Is Int Then
     '...
   Else
     ' invalid parameter
   End If


Also, the item index could be wrong, so I have to handle this situation.

Not now ! ;)
 

LucaMs

Expert
Licensed User
Longtime User
I could need two only functions; the parameter could be of type object and I could check it:
This line:
If IndexOrView Is View Then
produces an error:
An error occurred:
(Line: 179) If IndexOrView Is View Then
java.lang.ClassNotFoundException: java.lang.android.view.View


so I solved using a bit different way.

Attached Handle CustomListView V. 2 to the first post. It uses only two functions and checks if an item for the given item index exists.
 
Last edited:
Top