Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application I have multiple Array lists, (more than 20 in my case), trying to find a way to store them somewhere and call them back if possible, like in Modules in VB.

Here is my code

Models Class

public class Contacts
{
    [PrimaryKey][AutoIncrement]
    public int Contact_ID { get; set; }
    public string Contact_Name { get; set; }
    public string Contact_Address { get; set; }
    public string Contact_eMail { get; set; }
}


Main Page

public partial class MainPage : ContentPage
{
    readonly SQLiteAsyncConnection _connection 
        = DependencyService.Get<ISQLite>().GetConnection();

    public MainPage()
    {
        InitializeComponent();
        this.BindingContext = this;
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        // I have more than 20 This type of Array Lists, and some contains 
        more than 30 items 
        
        int[] intArray;
        intArray = new int[4];
        intArray[0] = 13;
        intArray[1] = 14;
        intArray[2] = 18;
        intArray[3] = 21;

        var list = _connection.Table<Contacts>().ToListAsync().Result;
        var myAL = new ArrayList();
        foreach (int rowList in intArray)
        {
            var NewItem = list.Where(x => x.Contact_ID.Equals(rowList));
            myAL.Add(NewItem.FirstOrDefault());
        }

        listView.ItemsSource = myAL;
    }
}


XAML Page

<StackLayout>
    <ListView x:Name="listView" HasUnevenRows="True"  IsVisible="True">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Orientation="Vertical" VerticalOptions="CenterAndExpand">
                        <Frame BackgroundColor="LightYellow">
                            <StackLayout Orientation="Vertical" VerticalOptions="Center" >
                                <Label Text="{Binding Contact_Name}" HorizontalOptions="StartAndExpand" TextColor="Black" FontSize="Medium"></Label>
                                <Label Text="{Binding Contact_Address}" HorizontalOptions="StartAndExpand" TextColor="Black" FontSize="Medium"></Label>
                                <Label Text="{Binding Contact_eMail}" HorizontalOptions="StartAndExpand" TextColor="Black" FontSize="Medium"></Label>
                            </StackLayout>
                        </Frame>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>


What I have tried:

Need to display selective contacts from DB file using intArray lists
Posted
Updated 31-Oct-20 4:59am

1 solution

Create a "data class" containing your arrays. Serialize the data class (to XML or binary) and restore when you need it.

I serialize (and compress, in some cases) the data class and add it as an embedded resource which I retrieve and deserialize at run time in the main EXE; or add it to a separate DLL.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900