我正试图通过Xamarin来掌握Android上的线程系统。
我想使用一个线程在后台执行一些代码,然后根据ui thread / fragment中该代码的返回值做出决定。
目前我是这样实现的:
DataRecordingFragment.cs
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.DataListFragment, container, false);
Activity.Title = "My Data List";
ListView lv = (ListView)v.FindViewById(Resource.Id.dataListView);
lv.Adapter = new DataListItemAdapter(this.Activity, _dataList);
lv.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {
var listView = sender as ListView;
var dataItem = _dataList[e.Position];
OptionsPopup(path, dataItem.Filename, listView, v.Context);
};
return v;
}
private void OptionsPopup(string path, string dataname, ListView lv, Android.Content.Context c)
{
var builder = new AlertDialog.Builder(this.Activity);
builder.SetPositiveButton("Open", (sendere, args) =>
{
// open data file using intent
})
.SetNeutralButton("Delete", (senderee, args)
{
// delete data file.
})
.SetTitle(dataname)
.Show();
}
DataListingFragment.cs
lv.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {
var listView = sender as ListView;
var dataItem = _dataList[e.Position];
OptionsPopup(path, dataItem.Filename, listView, v.Context);
};
单击列表视图项时应用程序崩溃:
<data-view [records]="records"
(sendCache)="onValuesReceived($event, type = 'location')"
(sendOrigFile)="onValuesReceived($event, type = 'origFile')"
(sendStart)="onValuesReceived($event, type = 'start')"
(sendEnd)="onValuesReceived($event, type = 'end')">
</data-view>
有什么想法吗?感谢。