Я использую xamarin, и в настоящее время я использую пользовательский адаптер массива, но мой проф. сказал мне, что наша система должна включать базу данных, поэтому я продолжал искать, пока не нашел json, но кто-то сказал мне, что я могу получить мои данные быстрее, если я использую SQlite. Так я и сделал .. Я уже создал свой собственный предварительно заполненный файл базы данных SQLite с помощью SQLite Manager (плагин firefox). Я слежу за этим link, чтобы использовать свой собственный файл базы данных SQLite. Я не знаю, что делать дальше .. искал почти 2 часа, но не нашел полезных примеров. жаль, что вы программист noob. может ли кто-нибудь дать мне полезные ссылки?как заполнить список из собственного файла sqlite?
то, что я до сих пор:
public class DBOpenHelper:SQLiteOpenHelper
{
private static string DB_PATH = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
private static string DB_NAME = "akyatpinas.db";
private static int VERSION = 1;
private Context context;
public DBOpenHelper(Context context) : base(context, DB_NAME, null, VERSION)
{
this.context = context;
}
private string GetSQLiteDBPath()
{
return Path.Combine(DB_PATH, DB_NAME);
}
public override SQLiteDatabase WritableDatabase
{
get { return CreateSQLiteDB(); }
}
private SQLiteDatabase CreateSQLiteDB()
{
SQLiteDatabase sqliteDB =null;
string path = GetSQLiteDBPath();
Stream streamSQLite = null;
FileStream streamWriter = null;
Boolean isSQLiteInit = false;
try
{
if (File.Exists(path))
isSQLiteInit = true;
else
{
streamSQLite = context.Resources.OpenRawResource(Resource.Raw.akyatpinas);
streamWriter = new FileStream(path,FileMode.OpenOrCreate,FileAccess.Write);
if (streamSQLite != null && streamWriter != null)
{
if (CopySQLiteDB(streamSQLite, streamWriter))
isSQLiteInit = true;
}
}
if (isSQLiteInit)
sqliteDB = SQLiteDatabase.OpenDatabase(path, null, DatabaseOpenFlags.OpenReadonly);
}
catch
{
// ignored
}
return sqliteDB;
}
private bool CopySQLiteDB(Stream readStream, FileStream writeStream)
{
bool isSuccess = false;
int length = 256;
Byte[] buffer = new Byte[length];
try
{
// write the required bytes
int bytesRead = readStream.Read(buffer, 0, length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, length);
}
isSuccess = true;
}
catch
{
//ignore
}
finally
{
readStream.Close();
writeStream.Close();
}
return isSuccess;
}
public override void OnCreate(SQLiteDatabase db)
{
}
public override void OnUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
throw new NotImplementedException();
}
}
да, сэр .. Я создал его, но моя проблема в том, что я не знаю, как манипулировать им. отредактировал мой пост – chlara