Java Question How to use Type in a library and pass it to b4a?

claude330

Member
Licensed User
Longtime User
I am looking to create a library passing to b4a a table like this:

Id Title Type Editor
1 ABC Romance xxxxx
2 DEF Historical yyyyy
3 GHI Romance zzzzz

With java I begin with

public Map MyMap(String Param)
........
........
Map1 Map = new Map();
Map1.initialize;
List1 List = new List();
List1.initialize;
.......
List1.Add("ABC");
List1.Add("Romance");
List1.Add("xxxxx");
and so on....
.......
.......
Map1.put(1,List1);
and so on.....
.......
return Map1;
........

B4a program:

Dim Map1 as Map
Map1.Initialize
Map1=Library.MyMap("1952")

I have the result, but I think that this code isn't probably a good code:
1 Is 'Map' + 'List' the best solution to pass the table ?
2 How can I use Type Book(B_Id as int, B_Title as String,....) to semplify the code? For example the phone library has a Contacts2 class and also a Contact Type.

Thanks
 

claude330

Member
Licensed User
Longtime User
Because I have to keep some informations from ContactsContract like IM and others and isn't possible with Phone Library or FGContacts. Than I have to work with Java.
 

claude330

Member
Licensed User
Longtime User
The same I don't understand how to procced.This is my library code:
B4X:
public class TestRubrica {
   /**
    * Returns IM map informations 
    * ID_Contact - The ID to search
    */
   public Map ImMapById(int Id_Contact) {
      Map M1 = new Map();
      M1.Initialize();
      List L1 = new List();
      L1.Initialize();
      ContentResolver cr = BA.applicationContext.getContentResolver();
      String imWhere = ContactsContract.Data.CONTACT_ID + " = ? AND "
            + ContactsContract.Data.MIMETYPE + " = ?";
      String[] imWhereParams = new String[] { String.valueOf(Id_Contact),
            ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE };
      Cursor imCur = cr.query(ContactsContract.Data.CONTENT_URI, null,
            imWhere, imWhereParams, null);
      /** if (imCur.moveToFirst()) { */
      if (imCur.getCount() > 0) {
         while (imCur.moveToNext()) {
            String imName = imCur
                  .getString(imCur
                        .getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA));
            String imType;
            imType = imCur
                  .getString(imCur
                        .getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE));
            String imProtocol;
            imProtocol = imCur
                  .getString(imCur
                        .getColumnIndex(ContactsContract.CommonDataKinds.Im.PROTOCOL));
            
            L1.Add(imType);
            L1.Add(imName);
            L1.Add(imProtocol);

            AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), L1);
            M1.Put(Id_Contact,L1);
         } 
      }
      imCur.close();
      AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), M1);
      return M1;
   }

I wrote the three lines L1.Add() only because i don't understand how to use array in Java. In B4A i want to write something like this:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim mm As TestRubrica
   
   Type IMFields(IM_Type,IM_Title,IM_Protocol)
   Dim IMF1 As IMFields
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")

      Dim Stream1 As Map
      Stream1.Initialize
      Stream1=mm.ImMapById(10)
      Dim ListOfIM As List
      ListOfIM.Initialize
      For k = 0 To Stream1.Size - 1
      
               ' ... somethink like 
                ListOfIM.add(Stream1.GetValueAt(k))
                        For y=0 to ListOfIM.Size -1
                          IMFields=ListOfIM.Get(y)
                           ...
                           Dim a, b, c as String
                           a=IMFields.IM_Type
                           b=IMFields.IM_Title
                           c=IMFields.IM_Protocol
                          Next
      Next

Where IMFields isn't coded because i don't know how to resolve the class in the library.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…