ボタンを SupportMapFragment の上で動作させようとしていますが、OnclickListener が起動しません。これが私のコードです:
マップフラグメント:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
setRetainInstance(true);
SP = getActivity().getSharedPreferences(SHARED_PREFS_NAME, 0);
this.SP.registerOnSharedPreferenceChangeListener(this);
View view = inflater.inflate(R.layout.map, container, false);
FrameLayout frameLayout = new FrameLayout(getActivity());
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
((ViewGroup) view).addView(frameLayout, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
setHasOptionsMenu(true);
tracker = GoogleAnalyticsTracker.getInstance();
setMapTransparent((ViewGroup) view);
String mapType = SP.getString("PREF_MAP", "MAP_TYPE_NORMAL");
FragmentManager myFragmentManager = getFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
if (mapType.equals("MAP_TYPE_NORMAL")) {
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
} else if (mapType.equals("MAP_TYPE_SATELLITE")) {
myMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
} else if (mapType.equals("MAP_TYPE_HYBRID")) {
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
myMap.setMyLocationEnabled(true);
myMap.setOnMapClickListener(this);
myMap.setOnMapLongClickListener(this);
myMap.getUiSettings().setZoomControlsEnabled(true);
myMap.getUiSettings().setMyLocationButtonEnabled(true);
myMap.getUiSettings().setScrollGesturesEnabled(true);
myMap.getUiSettings().setZoomGesturesEnabled(true);
((Activity) getActivity()).setSupportProgressBarIndeterminateVisibility(false);
button = (Button) view.findViewById(R.id.sbutton);
this.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "CLICK!", Toast.LENGTH_SHORT).show();
}
});
return view;
}
map.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:holo="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main"
>
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
<Button
android:id="@+id/sbutton"
android:layout_width="48dp"
android:layout_height="48dp"
android:gravity="center_horizontal|center_vertical"
android:background="@drawable/ic_social_share_light"
/>
なぜ機能しないのかわからない。誰かがコードを見て、私が間違っていることを教えてもらえますか?
ありがとう