У меня есть класс, который получает долготу и широту с устройства пользователя и сохраняет его в базе данных SQLite.Вот код:
[Activity(Label = "GetLocation")]
public class GetLocation : Activity, ILocationListener
{
Button btncreate;
EditText txtlong;
EditText txtlat;
static readonly string TAG = "X:" + typeof(GetLocation).Name;
Location _currentLocation;
LocationManager _locationManager;
string _locationProvider;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GetLocation);
txtlong = FindViewById<EditText>(Resource.Id.txtlong);
txtlat = FindViewById<EditText>(Resource.Id.txtlat);
btncreate = FindViewById<Button>(Resource.Id.btnvalidate);
btncreate.Click += Btncreate_Click;
InitializeLocationManager();
}
void InitializeLocationManager()
{
_locationManager = (LocationManager) GetSystemService(LocationService);
Criteria criteriaForLocationService = new Criteria
{
Accuracy = Accuracy.Fine
};
IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
if (acceptableLocationProviders.Any())
{
_locationProvider = acceptableLocationProviders.First();
}
else
{
_locationProvider = string.Empty;
}
Log.Debug(TAG, "Using " + _locationProvider + ".");
}
public void OnProviderDisabled(string provider) { }
public void OnProviderEnabled(string provider) { }
public void OnStatusChanged(string provider, Availability status, Bundle extras) { }
protected override void OnResume()
{
base.OnResume();
_locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
}
protected override void OnPause()
{
base.OnPause();
_locationManager.RemoveUpdates(this);
}
public void OnLocationChanged(Location location)
{
_currentLocation = location;
if (_currentLocation == null)
{
txtlong.Text = "Unable to determine your location. Try again in a short while.";
txtlat.Text = "Unable to determine your location. Try again in a short while.";
}
else
{
txtlong.Text = _currentLocation.Longitude.ToString();
txtlat.Text = _currentLocation.Latitude.ToString();
}
}
private void Btncreate_Click(object sender, EventArgs e)
{
try
{
string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Location.db3");
var db = new SQLiteConnection(dpPath);
db.CreateTable<DataTable>();
DataTable tbl = new DataTable();
tbl.Longitude = txtlong.Text;
tbl.Latitude = txtlat.Text;
db.Insert(tbl);
NextPage();
Toast.MakeText(this, "Data Store Successfully...,", ToastLength.Short).Show();
}
catch (Exception ex)
{
Toast.MakeText(this, ex.ToString(), ToastLength.Short).Show();
}
}
void NextPage()
{
//code to get next page
}
}
класс DataTable выглядит следующим образом:
class DataTable
{
[PrimaryKey, AutoIncrement, Column("_Id")]
public int Id {get; set;}
public string Longitude { get; set; }
public string Latitude { get; set; }
}
после того, как данные сохранены, я бы хотел, чтобы другой класс (вид деятельности) мог их отображатьна отдельной странице .axml.Моя проблема в том, что я программист на тренинге (в колледже) и понятия не имею, что делать.Ваша помощь очень ценится.