【问题标题】:Spinner only retrieving the first item from SQL Server databaseSpinner 仅从 SQL Server 数据库中检索第一项
【发布时间】:2016-05-18 13:27:58
【问题描述】:

我的 WCF Web 服务上有这个:

public List<string> GetLocation()
{
    InsertToFSRDataContext context = new InsertToFSRDataContext();

    var loc = from z in context.Parameters where z.ParamGroup == "LOCATION" orderby z.ParamValue ascending select z.ParamDesc;

    return loc.ToList<string>();
}

MainActivity.cs

protected override void OnCreate(Bundle bundle)
{
   SetContentView(Resource.Layout.Main);
   BasicHttpBinding binding = CreateBasicHttp();
   _client = new FSRServiceClient(binding, EndPoint);
   _client.GetLocationCompleted += ClientOnGetLocationCompleted;
   _client.GetLocationAsync();
}

private void ClientOnGetLocationCompleted(object sender, GetLocationCompletedEventArgs getLocationCompletedEventArgs)
{
   spinner1 = FindViewById<Spinner>(Resource.Id.spinner1);
   List<string> list = new List<string>(getLocationCompletedEventArgs.Result);
   ArrayAdapter<string> adapter1 = new ArrayAdapter<string>(this, Resource.Drawable.spinner_item, list);
   spinner1.Adapter = adapter1;
}

在我的安卓模拟器上,它只显示微调器上的第一项。这可能是什么问题?

【问题讨论】:

  • 从 WCF 发送时有多少项目?
  • @AnupSharma 仅 17 项,所以我不知道为什么它没有显示在微调器上
  • 在函数ClientOnGetLocationCompleted中,调试时你是否在第二行得到了所有17项?
  • @AnupSharma 所以我再次运行该应用程序然后出现此错误:Unhandled Exception: Java.Lang.ArrayIndexOutOfBoundsException: length=18; index=-1
  • 出于某种原因,我可以很好地运行它,但只显示微调器上的第一项,但有时我会得到 java.lang 未处理的异常。

标签: c# android wcf xamarin spinner


【解决方案1】:

我通过添加RunOnUiThread(() 解决了这个问题。没想到这么容易解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 2019-01-20
    • 2013-07-25
    • 1970-01-01
    相关资源
    最近更新 更多