0
我要问的命令,我应该使用从一个类通过项目的数组的主要活动,然后使用这个数组的项目来填充列表视图传递数组Xamarin的Android
var result = webservice.salesOrderList(apikey, null);
我必须将结果传递给主要活动,然后在列表视图中使用它。
我要问的命令,我应该使用从一个类通过项目的数组的主要活动,然后使用这个数组的项目来填充列表视图传递数组Xamarin的Android
var result = webservice.salesOrderList(apikey, null);
我必须将结果传递给主要活动,然后在列表视图中使用它。
例如,如果你的var result = webservice.salesOrderList(apikey, null) ;
结果是一个字符串数组,你可以在你的类定义了这样的结果,例如像这样:
public class DataSource
{
public string[] result { get; set; }
public DataSource()
{
result = webservice.salesOrderList(apikey, null);
}
}
然后创建您的适配器连接到数据源类型的字符串数组匹配例如:
public class MainAdapter : BaseAdapter<string>
{
private string[] items;
private Activity context;
public MainAdapter(Activity context, string[] items) : base()
{
this.context = context;
this.items = items;
}
public override string this[int position]
{
get
{
return items[position];
}
}
public override int Count
{
get
{
return items.Length;
}
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
view = context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem1, null);
view.FindViewById<TextView>(Android.Resource.Id.Text1).Text = items[position].ToString();
return view;
}
}
最后使用该适配器为您ListView
:
public class MainActivity : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var data = new DataSource();
ListAdapter = new MainAdapter(this, data.result);
}
}
这是创建ListView
的最简单方法,您当然可以自定义您的项目样式或ListView
。有关在Xamarin.Android中创建ListView
的更多信息,请参阅ListViews and Adapters。