无法解析方法getSupportFragmentManager

时间:2015-09-02 18:10:57

标签: android

这里我得到错误:"无法解析方法getSupportFragmentManager"虽然我已经为它添加了import语句。我似乎无法理解这个问题。有人可以帮忙吗?

以下是代码:

package com.example.veeresh.parsegeo;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class AgentsDropdownOnItemClickListener  implements OnItemClickListener {
public String selectedItemTag;

public GoogleMap mMap;
MapsActivity agent = new MapsActivity();

@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {


    Context mContext = v.getContext();
    MapsActivity mainActivity = ((MapsActivity) mContext);


    Animation fadeInAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_in);
    fadeInAnimation.setDuration(10);
    v.startAnimation(fadeInAnimation);


    mainActivity.popupWindowDogs.dismiss();



    selectedItemTag = ((TextView) v).getTag().toString();
    if ( selectedItemTag.equals("VISA")) {
        Toast.makeText(mContext, "Agent ID is: ", Toast.LENGTH_SHORT).show();
        if (mMap == null) {
                        // Try to obtain the map from the SupportMapFragment.
                        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                                .getMap();
                        // Check if we were successful in obtaining the map.
                        if (mMap != null) {
                           agent.setUpMapVisa();
                        }
                    }
        mMap.clear();
        agent.setUpMapAadhar();
    }



}

}

3 个答案:

答案 0 :(得分:0)

您应该为课程延长FragmentActivity。如下所示

public class AgentsDropdownOnItemClickListener extends FragmentActivity  implements OnItemClickListener{

有关详细信息,请参阅docs

答案 1 :(得分:0)

你显然没有展示整个活动。

在任何情况下,您应该做的是确保实际包含地图的活动是您要求查找视图的活动。

这意味着: 如果地图视图位于“MapsACtivity”,您应该写下这样的内容:

mMap = ((SupportMapFragment) mainActivity.getSupportFragmentManager().findFragmentById(R.id.map))
                            .getMap();

当然要确保mainActivity扩展FragmentActivity。

可以找到有关findViewByID的更多信息here

答案 2 :(得分:0)

尝试代替public class MainActivity extends Activity

public class MainActivity extends FragmentActivity

同时检查并确保导入SupportLibrary,如:

import android.support.v4.app.Fragment;

现在,您可以使用getSupportFragmentManager()