Reputation: 397
I am new to Xamarin Forms and Xamarin in general. I may be misunderstanding how the architecture works, or I may be following a mix of different examples online. I am trying to use as much of the Portable Class Library
as possible.
My nuget packages are Xamarin.Forms
and SQLite.Net-PCL
. They are installed on all, Droid, ios, windows, and PCL. Definitely the most recent verified highest downloaded. I am following these guides
https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/
On the SQLite_Droid implementation of the SQLite interface, I do not have access to the Xamarin.Forms using statement or the one that has the Interface, Here is all the code in the Native_PCL
Project.
ISQLite.cs
using SQLite.Net;
namespace Native_PCL.DataServices
{
interface ISQLite
{
SQLiteConnection GetConnection();
}
}
DataCalls.cs
using System.Linq;
using SQLite.Net;
using Xamarin.Forms;
using Native_PCL.Data;
namespace Native_PCL.DataServices
{
public class DataCalls
{
static object locker = new object();
SQLiteConnection db;
public DataCalls()
{
db = DependencyService.Get<ISQLite>().GetConnection();
db.CreateTable<UserPreferences>();
db.CreateTable<Orders>();
}
public void SubmitData(Orders order, out string update)
{
lock (locker)
{
if (!db.Table<Orders>().Any(x => x.foodName == order.foodName))
{
db.Insert(order);
update = order.foodName;
}
else { update = order.foodName + " was already in your Order"; }
}
}
}
}
Here is all the code in the Native_PCL.Droid
project
SQLite_Droid.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content; // for some reason all of the System. and Android. are showing white. Usually unused statements are grayed out!
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Native_PCL;
using Native_PCL. ; /// only .Droid is registering
using Xamarin.Forms; //Intellisense does not pick this up
namespace Native_PCL.Droid.DataImplement
{
public class SQLite_Droid : Native_PCL.DataServices.ISQLite /// All white, Doesn't register the ISQLite as an Interface.
{
}
}
I have recreated the entire project. I must be doing something completely wrong.
Upvotes: 0
Views: 464
Reputation: 397
After pulling out most of my hair, I had to think, it couldn't possibly be me. I compiled and there were several errors. I decided to go to the MainActivity.cs
in the Android solution. it turns out that the boiler plate fresh project could not find App
. Here were the steps to resolve my issue.
go to /Users/XXXXXX/AppData/Local/Xamarin
I deleted all the folders except for log and zips, I deleted the zipped file within the zip folder though.
Go to Solution Explorer, right click on solution, and Clean Solution
.
Portable Class library
project from the Android project.Portable Class library
project.The lesson of the story is, if you ever have intellisense issues that are not picking up references that should be there, follow steps 2, 3, 4, 5 . And because it's Xamarin and involves emulators and cross-compatability, follow step 1.
Upvotes: 1