本文介绍了如何在Volley,Android中制作新的newRequestQueue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个片段,尝试使用Volley API实例化新的newRequestQueue.

I have an fragment where I try to Instantiate a new newRequestQueue with the Volley API.

我尝试这样实例化它:

RequestQueue queue = Volley.newRequestQueue(this);

但是,当我尝试创建请求时,出现以下错误:

However, when I try to create the request, I get the following error:

newRequestQueue In Volley cannot be applied to annonymous android.view.View.OnClickListener

这是我的Fragment类:

Here is my Fragment class:

public class LoginFragment extends Fragment {
    private FacebookLogin fLogin;
    private Profile profile;
    private CallbackManager mCallbackManager; //Used in activity result below. Gets a value when u hit the button
    private static final String TAG = "Event";
    private static String url_create_user = "127.0.0.1/create_row.php";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fLogin = new FacebookLogin(getActivity().getApplicationContext());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v =  inflater.inflate(R.layout.login, container, false);
        return v;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);

        final LoginButton loginButton = (LoginButton) getView().findViewById(R.id.login_button);
        final TextView infoText = (TextView) getView().findViewById(R.id.text_details);
        final ImageView profilP = (ImageView) getView().findViewById(R.id.profilePicture);

        loginButton.setFragment(this);


        loginButton.setReadPermissions("user_friends");

        loginButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.i(TAG, " Button clickde");
                fLogin.setCallback(loginButton); //Let's register a callback

                RequestQueue queue = Volley.newRequestQueue(this);

                fLogin.setFacebookListener(new FacebookLogin.OnFacebookListener() {
                    @Override
                    public void onFacebookLoggedIn(JSONObject parameters) {
                        Log.i(TAG, "INNNNNNNNNNNE");
                        Log.i(TAG, parameters.toString());
                    }
                });
            }
        });

    }

   @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mCallbackManager = fLogin.getCallbackManager(); //Get the callbackmanager
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
    }

}

推荐答案

newRequestQueue的参数是一个Context对象.在您的情况下,这指的是View.OnClickListener匿名内部类,您在其中调用newRequestQueue.更改

the parameter of newRequestQueue is a Context object. In your case, this, refers to the View.OnClickListener anonymous inner class, where you are calling newRequestQueue. Change

Volley.newRequestQueue(this);

使用

 Volley.newRequestQueue(getActivity().getApplicationContext());

当然,

getActivity(),因为您是Fragment

is, of course, getActivity() because you are subclassing Fragment

这篇关于如何在Volley,Android中制作新的newRequestQueue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 21:28