[英]Call on an Async Task from main activity to a fragment
I have an async task that needs to initilize on a button click inside my bottomsheet fragment.我有一个异步任务,需要在我的底页片段内单击按钮时进行初始化。 However when I call on the method from my bottomsheet fragment with但是,当我从我的底页片段调用该方法时
private async void _navigationButton_Click(object sender, EventArgs e)
{
await ((MainActivity)Activity).Routing();
}
I get the error:我得到错误:
CS7036 There is no argument given that corresponds to the required formal parameter 'p' of 'MainActivity.Routing(MapPoint)' Maps. CS7036 没有给出与“MainActivity.Routing(MapPoint)”地图所需的形式参数“p”相对应的参数。
The code below is my method for getting a route when clicking on a mappoint on the map in my mainactivity.下面的代码是我在我的 mainactivity 中单击 map 上的地图点时获取路线的方法。
try
{
_textToSpeech = new TextToSpeech(this, this, "com.google.android.tts");
Stop stop0 = new Stop(_startPoint) { Name = "Starting Point" };
// Stop stop1 = new Stop(_endPoint) { Name = "EndPoint" };
if (_endPoint == null)
{
await _geocoder.ReverseGeocodeAsync(p);
_endPoint = p;
RouteTask routeTask = await RouteTask.CreateAsync(_routingUri);
RouteParameters routingParameters = await routeTask.CreateDefaultParametersAsync();
List<Stop> stops = new List<Stop> { new Stop(_startPoint), new Stop(_endPoint) };
routingParameters.SetStops(stops);
RouteResult result = await routeTask.SolveRouteAsync(routingParameters);
Route firstRoute = result.Routes.First();
_routeAheadGraphic = new Graphic(firstRoute.RouteGeometry) { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Blue, 4) };
SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.Red, 2) }; _myMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic);
await _myMapView.SetViewpointGeometryAsync(firstRoute.RouteGeometry, 100);
return;
}
If the mappoint is not available in Fragment, you could define a public method in Main activity first, call Routing(mapPoint)
inside that method.如果 mappoint 在 Fragment 中不可用,您可以先在 Main 活动中定义一个公共方法,在该方法中调用Routing(mapPoint)
。
public void MyMethod(){
Routing(mapPoint);
}
private async void _navigationButton_Click(object sender, EventArgs e)
{
await ((MainActivity)Activity).MyMethod();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.