0
だから、私は手動で使用にコードを挿入したSQLiteデータベースを有するレイアウトで表示されないC#のアンドロイド - SQLiteのデータベースは
public class Fixtures_SQLiteDB
{
private string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
public bool createDataBase()
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "SphereSports.db")))
{
connection.CreateTable <FixtureItem>();
//connection.Execute("Drop TABLE [Person]", "");
connection.Execute("CREATE TABLE [Fixture] ([FixtureID] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, [CompetitionID] INTEGER NOT NULL, [DATE] DATETIME NOT NULL,[KICKOFF] DATETIME NULL, [HomeTeamID] INTEGER NOT NULL ,[AwayTeamID] INTEGER NOT NULL)", "");
connection.Execute(String.Format("Insert Into [Fixture] ([CompetitionID],[Date],[KickOff],[HomeTeamID],[AwayTeamID]) Values ({0},{1},{2},{3},{4})", "2","2016-02-04","1400","1","3"), "");
connection.Execute(String.Format("Insert Into [Fixture] ([CompetitionID],[Date],[KickOff],[HomeTeamID],[AwayTeamID]) Values ({0},{1},{2},{3},{4})", "4", "2016-02-04", "1400", "2", "4"), "");
connection.Execute(String.Format("Insert Into [Fixture] ([CompetitionID],[Date],[KickOff],[HomeTeamID],[AwayTeamID]) Values ({0},{1},{2},{3},{4})", "5", "2016-03-04", "1400", "5", "7"), "");
connection.Execute(String.Format("Insert Into [Fixture] ([CompetitionID],[Date],[KickOff],[HomeTeamID],[AwayTeamID]) Values ({0},{1},{2},{3},{4})", "1", "2016-04-04", "1400", "6", "8"), "");
connection.Execute(String.Format("Insert Into [Fixture] ([CompetitionID],[Date],[KickOff],[HomeTeamID],[AwayTeamID]) Values ({0},{1},{2},{3},{4})", "3", "2016-05-04", "1400", "9", "11"), "");
connection.Execute(String.Format("Insert Into [Fixture] ([CompetitionID],[Date],[KickOff],[HomeTeamID],[AwayTeamID]) Values ({0},{1},{2},{3},{4})", "4", "2016-06-04", "1400", "10", "12"), "");
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public List<FixtureItem> selectTableFixtureItem()
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "SphereSports.db")))
{
return connection.Query<FixtureItem>("SELECT * FROM [Fixture]", "").ToList();
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return null;
}
}
}
}
Iは、テーブルからの列に応じて行を示すべきリストビューを有します。
public class ViewHolder : Java.Lang.Object
{
public TextView txtfixID { get; set; }
public TextView txtcompID { get; set; }
public TextView txtdate { get; set; }
public TextView txtkickoff { get; set; }
public TextView txthomeID { get; set; }
public TextView txtawayID { get; set; }
}
public class ListViewAdapter : BaseAdapter
{
private Activity activity;
private List<FixtureItem> lstFixture;
public ListViewAdapter(Activity activity, List<FixtureItem> lstFixtures)
{
this.activity = activity;
this.lstFixture = lstFixtures;
}
public override int Count
{
get
{
return lstFixture.Count;
}
}
public override Java.Lang.Object GetItem(int position)
{
return null;
}
public override long GetItemId(int position)
{
return lstFixture[position].FixtureItemID;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = convertView ?? activity.LayoutInflater.Inflate(Resource.Layout.list_view_dataTemplate, parent, false);
var txtfixID = view.FindViewById<TextView>(Resource.Id.textViewFixtureID);
var txtcompID = view.FindViewById<TextView>(Resource.Id.textViewCompID);
var txtdate = view.FindViewById<TextView>(Resource.Id.textViewDate);
var txtkickoff = view.FindViewById<TextView>(Resource.Id.textViewKickOff);
var txthomeID = view.FindViewById<TextView>(Resource.Id.textViewHomeID);
var txtawayID = view.FindViewById<TextView>(Resource.Id.textViewAwayID);
txtfixID.Text = "" + lstFixture[position].FixtureItemID;
txtcompID.Text = "" + lstFixture[position].CompetitionID;
txtdate.Text = "" + lstFixture[position].Date;
txtkickoff.Text = lstFixture[position].KickOff;
txthomeID.Text = "" + lstFixture[position].HomeTeamID;
txtawayID.Text = "" + lstFixture[position].AwayTeamID;
return view;
}
}
}
アプリはAndroidエミュレータで問題なく実行されますが、SQLiteデータベース内にあるはずのフィールドは表示されません。何が起こっているのか何か問題がありますか?ここで
は、うまくいけば、問題解決に役立つ多くのコード...
public class NewDatabaseActivity : Activity
{
ListView lstData;
List<FixtureItem> lstSource = new List<FixtureItem>();
Fixtures_SQLiteDB db;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.upcomf);
//Create DataBase
db = new Fixtures_SQLiteDB();
db.createDataBase();
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
Log.Info("DB_PATH", folder);
lstData = FindViewById<ListView>(Resource.Id.listView);
LoadData();
lstData.ItemClick += (s, e) =>
{
//Binding Data
var txtfixID = e.View.FindViewById<TextView>(Resource.Id.textViewFixtureID);
var txtcompID = e.View.FindViewById<TextView>(Resource.Id.textViewCompID);
var txtdate = e.View.FindViewById<TextView>(Resource.Id.textViewDate);
var txtkickoff = e.View.FindViewById<TextView>(Resource.Id.textViewKickOff);
var txthomeID = e.View.FindViewById<TextView>(Resource.Id.textViewHomeID);
var txtawayID = e.View.FindViewById<TextView>(Resource.Id.textViewAwayID);
};
}
private void LoadData()
{
lstSource = db.selectTableFixtureItem();
var adapter = new ListViewAdapter(this, lstSource);
lstData.Adapter = adapter;
}
}
}