【发布时间】:2020-10-30 19:51:35
【问题描述】:
在我的应用程序中,我有多个数组列表(在我的情况下超过 20 个),试图找到一种方法将它们存储在某个地方并在可能的情况下将它们回调。就像 VB 模块中的旧方法一样。这是我的代码!
模型类代码
公开课联系人
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; }
}
主页
`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 页面
`<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>`
【问题讨论】:
-
您可以将 ArrayLists 转换为 json 字符串,然后通过键值对Preferences 保存并获取它。
-
感谢@Leo Zhu - MSFT 的回复,我会检查一下,会通知您
标签: xamarin arraylist xamarin.forms