Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

android - MarkerClick works but InfoWindowClick does not open ViewModel

The following MarkerClick implementation works, perfectly fine. I could be able to open other Views via ShowViewModel

View.cs

mMap.MarkerClick += MMap_MarkerClick;

private void MMap_MarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
{
   ViewModel.MapInfoSelected(e.Marker.Title);
}

ViewModel.cs

public void MapInfoSelected(string name)
{
    ShowViewModel<StudentViewModel>(new { studentName = name});
}

InfoWindowClick does not trigger to open other View.

View.cs

mMap.InfoWindowClick += MMap_InfoWindowClick;

private void MMap_InfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
{
  ViewModel.MapInfoSelected(e.Marker.Title);
}

ViewModel.cs

public void MapInfoSelected(string name)
{
 // it hits here, but does not hit `StudentViewModel` Init() method, the app is frozen and do nothing
    ShowViewModel<StudentViewModel>(new { studentName = name});
}

I even tried the SetOnInfoWindowClickListener as follows, it also does not open the View.

 mMap.SetOnInfoWindowClickListener(this);

 public void OnInfoWindowClick(Marker marker)
 {
     ViewModel.MapInfoSelected(marker.Title);
 }

UPDATE:

It even hits the OnPause() method, but still it does not call StudentViewModel Init() method if I use InfoWindowClick event

 public override void OnPause()
 {
   base.OnPause();
   mMap.InfoWindowClick -= MMap_InfoWindowClick;
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In onCreate, put mViewModel.getLiveData().observe(this, new Observer<List<YOUR STUFF>>(){ and in the .observe put the init() method, that is what works for me


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...