Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在标记位置获取上下文?_Android - Fatal编程技术网

Android 如何在标记位置获取上下文?

Android 如何在标记位置获取上下文?,android,Android,我正在尝试在我的android应用程序中使用parse.com,如何在code AlertDialog.Builder(******)中的***位置获取上下文?我试过使用getApplicationcontext,但它不起作用。有android经验的人能帮我解决这个问题吗 mSignInButton.setOnClickListener(new OnClickListener() { @Override public void onClick(Vi

我正在尝试在我的android应用程序中使用parse.com,如何在code AlertDialog.Builder(******)中的***位置获取上下文?我试过使用getApplicationcontext,但它不起作用。有android经验的人能帮我解决这个问题吗

mSignInButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                mVibrator.vibrate(100);

                //Checking for internet connection...
                 ConnectivityManager cm =
                            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                        NetworkInfo netInfo = cm.getActiveNetworkInfo();
                        //internet connection inactive... show alert...
                        if (!(netInfo != null && netInfo.isConnectedOrConnecting())) {
                            AlertDialog.Builder adb = new AlertDialog.Builder(arg0.getContext());
                            adb.setTitle("ALERT");
                            adb.setMessage("Please turn on Internet.");
                            adb.setPositiveButton("Ok", new DialogInterface.OnClickListener()
                            {
                                public void onClick(DialogInterface dialog, int id)
                                {
                                // Action for 'Ok' Button
                                 }
                            });
                            adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
                            {
                                            public void onClick(DialogInterface dialog, int id)
                                                            {
                                                            // Action for 'Cancel' Button
                                                            dialog.cancel();
                                            }
                            });
                            adb.setIcon(R.drawable.ic_launcher);
                            adb.show();
                         }else{                          
                             ParseQuery<ParseObject> query = ParseQuery.getQuery("Admin");
                             query.whereEqualTo("password", mUserNameEditText.getText().toString());
                             query.whereEqualTo("userName", mPasswordEditText.getText().toString());

                             query.countInBackground(new CountCallback() {
                                  public void done(int count, ParseException e) {
                                    if (e == null) {
                                      // The count request succeeded. Log the count
                                      Log.d("test", "Sean has played " + count + " games");
                                      if(count>0){
                                            // save the login status... loggedIn/notloggedIn...
                                            SharedPreferences sharedPreferences =   PreferenceManager.getDefaultSharedPreferences(LoginScreenActivity.this);
                                            SharedPreferences.Editor editor     =   sharedPreferences.edit();
                                            editor.putBoolean("isLoggedIn", true);
                                            editor.commit();

                                            // if user name password is correct, navigate to next activity...
                                            Intent intent   =   new Intent(LoginScreenActivity.this,OptionScreenActivity.class);
                                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                            startActivityForResult(intent, 0);
                                            overridePendingTransition(R.layout.fade_in, R.layout.fade_out);
                                        }else{
                                            AlertDialog.Builder adb = new AlertDialog.Builder(*********************);
                                            adb.setTitle("ALERT");
                                            adb.setMessage("Wrong username or password.");
                                            adb.setPositiveButton("Ok", new DialogInterface.OnClickListener()
                                            {
                                                public void onClick(DialogInterface dialog, int id)
                                                {
                                                // Action for 'Ok' Button
                                                 }
                                            });
                                            adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
                                            {
                                                            public void onClick(DialogInterface dialog, int id)
                                                                            {
                                                                            // Action for 'Cancel' Button
                                                                            dialog.cancel();
                                                            }
                                            });
                                            adb.setIcon(R.drawable.ic_launcher);
                                            adb.show();
                                        }

                                    } else {
                                      // The request failed

                                    }
                                  }
                                });                                                  
mSignInButton.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
振动(100);
//正在检查internet连接。。。
连接管理器cm=
(ConnectionManager)getSystemService(Context.CONNECTIVITY_服务);
NetworkInfo netInfo=cm.getActiveNetworkInfo();
//internet连接未激活…显示警报。。。
如果(!(netInfo!=null&&netInfo.isConnectedOrConnecting()){
AlertDialog.Builder adb=新建AlertDialog.Builder(arg0.getContext());
adb.setTitle(“警报”);
设置消息(“请打开互联网”);
adb.setPositiveButton(“确定”,新的DialogInterface.OnClickListener()
{
public void onClick(DialogInterface对话框,int-id)
{
//“确定”按钮的操作
}
});
adb.setNegativeButton(“取消”,新建DialogInterface.OnClickListener())
{
public void onClick(DialogInterface对话框,int-id)
{
//“取消”按钮的操作
dialog.cancel();
}
});
adb.setIcon(R.drawable.ic_启动器);
adb.show();
}否则{
ParseQuery=ParseQuery.getQuery(“Admin”);
query.whereEqualTo(“密码”,musernamedittext.getText().toString());
query.whereEqualTo(“用户名”,mPasswordEditText.getText().toString());
query.countInBackground(新的CountCallback(){
已完成公共void(整数计数,parsee异常){
如果(e==null){
//计数请求成功。请记录计数
Log.d(“测试”,“肖恩玩过”+count+“游戏”);
如果(计数>0){
//保存登录状态…loggedIn/notloggedIn。。。
SharedPreferences SharedPreferences=PreferenceManager.getDefaultSharedPreferences(loginsScreenActivity.this);
SharedReferences.Editor=SharedReferences.edit();
编辑器.putBoolean(“isLoggedIn”,true);
commit();
//如果用户名密码正确,请导航到下一个活动。。。
意向意向=新意向(LoginsScreenActivity.this,OptionScreenActivity.class);
intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
startActivityForResult(意向,0);
覆盖渐变(R.layout.fade\u in,R.layout.fade\u out);
}否则{
AlertDialog.Builder adb=新建AlertDialog.Builder(*******************);
adb.setTitle(“警报”);
设置消息(“错误的用户名或密码”);
adb.setPositiveButton(“确定”,新的DialogInterface.OnClickListener()
{
public void onClick(DialogInterface对话框,int-id)
{
//“确定”按钮的操作
}
});
adb.setNegativeButton(“取消”,新建DialogInterface.OnClickListener())
{
public void onClick(DialogInterface对话框,int-id)
{
//“取消”按钮的操作
dialog.cancel();
}
});
adb.setIcon(R.drawable.ic_启动器);
adb.show();
}
}否则{
//请求失败
}
}
});                                                  
按如下方式进行尝试:

    AlertDialog.Builder adb = new AlertDialog.Builder(getApplicationContext());

     AlertDialog.Builder adb = new AlertDialog.Builder(<YourActivity>.this);
AlertDialog.Builder adb=新建AlertDialo