我使用firesharp,我尝试在我的手机应用程序来获取数据,但是当我尝试它显示文本之前在启动应用程序崩溃。有没有什么办法,我做错了什么?或只是firesharp心不是应该对Xamarin。我用具有插入和检索,但在这里我只想取回,然后插入一个程序这样做已经
我的C-TY奇韦:
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using FireSharp.Config;
using FireSharp.Interfaces;
using FireSharp.Response;
using System.Threading;
using System;
namespace Quiz__
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
IFirebaseConfig config = new FirebaseConfig
{
AuthSecret = "Im hiding it",
BasePath = "Im hiding it"
};
IFirebaseClient client;
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
client = new FireSharp.FirebaseClient(config);
TextView txtQuestion = FindViewById<TextView>(Resource.Id.textQuestion);
var g = 2;
//g variable is just for the test
FirebaseResponse response = await client.GetAsync("question/"+g);
Data obj = response.ResultAs<Data>();
txtQuestion.Text = obj.question;
}
}
}
AHML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="@+id/textQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="35sp"
/>
</RelativeLayout>
数据类:
namespace Quiz__
{
internal class Data
{
public string Id { get; set; }
public string question { get; set; }
public string answer { get; set; }
public string hint { get; set; }
}
}
我用具有插入和检索,但在这里我只想取回,然后插入一个程序这样做已经
您可以在其他方法移动client.GetAsync(“提问/” + G),并没有为onCreate方法使用异步,并再次尝试您的项目。
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
client = new FireSharp.FirebaseClient(config);
txtQuestion = FindViewById<TextView>(Resource.Id.textQuestion);
//g variable is just for the test
test();
}
public async void test()
{
var g = "test1";
FirebaseResponse response = await client.GetAsync("question/" + g);
Data obj = response.ResultAs<Data>();
txtQuestion.Text = obj.question;
}