2

SupportMapFragment에서 작동하지만 OnclickListener가 실행되지 않는 버튼을 얻으려고합니다. 다음은 내 코드입니다 :OnClickListener가 Google지도 상단에있는 버튼과 작동하지 않습니다.

으로 MapFragment : 작동하지 않는 이유

<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" 
     /> 
이 몰라

@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. 누군가 코드를보고 내가 뭘 잘못하고 있는지 말해 줄 수 있습니까?

감사

+0

문제는 당신은 관련이없는 코드를 많이 게시됩니다. 도움이 필요하면 SSCCE.org를 제공하십시오. –

답변

1

문제를 해결했습니다. map.xml의 버튼에 onClick을 추가했으며 MapFragment의 코드를 사용하는 대신 MapActivity의 코드를 아래와 같이 사용했습니다. 이 방법은 내 버튼을 확인하고 있습니다.

Map.xml

android:onClick="sButton" 

MapActivity

public void sButton(View v) { 
    Toast.makeText(this, "CLICK!", Toast.LENGTH_SHORT).show(); 
} 
+0

멋진 본드 씨를 찾으세요! 고마워요! 이 경우에 onclicklistener가 작동하지 않는 이유는 무엇입니까? – Price

0

당신은 상단에 FrameLayout이를 addind 있습니다. 삭제 :

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)); 

setMapTransparent((ViewGroup) view); 
+0

여전히 작동하지 않습니다. – bond

+0

그럴만 한 이유는 없지만 setMapTransparent를 제거해보십시오. – Devrim

+0

그래, 이미 시도했다. 그래도 작동이 안되는. – bond

관련 문제