这是我应该调用的函数
public void myLocation (View v){
MyMapSettings(MY_LOCATION);
showMyAddressOnMap();
drawGeofencesAround(MY_LOCATION, false);
}
我从这里调用上面的函数:
@Override
public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) {
case R.id.add:
myLocation(View v); // I am getting error "Cannot resolve symbol".
return(true);
case R.id.reset:
//add the function to perform here
return(true);
case R.id.about:
//add the function to perform here
return(true);
case R.id.exit:
//add the function to perform here
return(true);
}
return(super.onOptionsItemSelected(item));
我想知道我应该将哪种 View 传递给我正在调用的函数?
最佳答案
似乎 public void myLocation (View v){
是一个点击监听器,因此创建一个新函数(随意命名)并将 myLocation
的代码移动到一个新功能
public void getLocation(){
MyMapSettings(MY_LOCATION);
showMyAddressOnMap();
drawGeofencesAround(MY_LOCATION, false);
}
然后像这样在任何地方调用它
public void myLocation (View v){
getLocation();
}
和
case R.id.add:
getLocation();
return(true);
或
如果你不想要这一切,那么只需传递 null
case R.id.add:
getLocation(null);
return(true);
关于android - 我应该将哪个 View 对象传递给以 View 对象作为菜单参数的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44247143/