我有一个片段我尝试使用Volley API实例化一个新的newRequestQueue
。
我尝试像这样实例化:
RequestQueue queue = Volley.newRequestQueue(this);
但是,当我尝试创建请求时,出现以下错误:
newRequestQueue In Volley cannot be applied to annonymous android.view.View.OnClickListener
这是我的片段类:
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);
}
}
任何可以帮助我的人?
答案 0 :(得分:9)
newRequestQueue
的参数是Context对象。在您的情况下,这是指View.OnClickListener
匿名内部类,您在其中调用newRequestQueue
。变化
Volley.newRequestQueue(this);
与
Volley.newRequestQueue(getActivity().getApplicationContext());
当然是getActivity()
,因为你是Fragment
答案 1 :(得分:0)
RequestQueue requestQueue = Volley.newRequestQueue(SignupActivity.this);
在这种情况下,SignupActivity
是您输入代码的活动。