久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='Rf5O3'></tfoot>

<small id='Rf5O3'></small><noframes id='Rf5O3'>

    <i id='Rf5O3'><tr id='Rf5O3'><dt id='Rf5O3'><q id='Rf5O3'><span id='Rf5O3'><b id='Rf5O3'><form id='Rf5O3'><ins id='Rf5O3'></ins><ul id='Rf5O3'></ul><sub id='Rf5O3'></sub></form><legend id='Rf5O3'></legend><bdo id='Rf5O3'><pre id='Rf5O3'><center id='Rf5O3'></center></pre></bdo></b><th id='Rf5O3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Rf5O3'><tfoot id='Rf5O3'></tfoot><dl id='Rf5O3'><fieldset id='Rf5O3'></fieldset></dl></div>

      • <bdo id='Rf5O3'></bdo><ul id='Rf5O3'></ul>
    1. <legend id='Rf5O3'><style id='Rf5O3'><dir id='Rf5O3'><q id='Rf5O3'></q></dir></style></legend>

      從其他方法訪問變量

      Access variables from another method(從其他方法訪問變量)
      <legend id='SKfik'><style id='SKfik'><dir id='SKfik'><q id='SKfik'></q></dir></style></legend>
        <tbody id='SKfik'></tbody>
      • <small id='SKfik'></small><noframes id='SKfik'>

        1. <tfoot id='SKfik'></tfoot>
            <bdo id='SKfik'></bdo><ul id='SKfik'></ul>

                <i id='SKfik'><tr id='SKfik'><dt id='SKfik'><q id='SKfik'><span id='SKfik'><b id='SKfik'><form id='SKfik'><ins id='SKfik'></ins><ul id='SKfik'></ul><sub id='SKfik'></sub></form><legend id='SKfik'></legend><bdo id='SKfik'><pre id='SKfik'><center id='SKfik'></center></pre></bdo></b><th id='SKfik'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SKfik'><tfoot id='SKfik'></tfoot><dl id='SKfik'><fieldset id='SKfik'></fieldset></dl></div>

                本文介紹了從其他方法訪問變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試使用當前位置在 android 中提交用戶注冊表單.我是 android 和 java 開發的新手.當我嘗試在我的名稱值對代碼中訪問 onLocationChanged 方法的 myLat 和 myLan 時,它無法找到這兩個變量.如何訪問我的名稱值對代碼中的兩個變量.

                i am trying to submit user registration form in android with current location. I am new to android and java development. when i try to access myLat and myLan of the onLocationChanged method in my name value pairs code , it is unable to find both the variables. How can i access both the variables in my name value pair code.

                package com.imran;
                
                import java.io.IOException;
                import java.util.ArrayList;
                import java.util.List;
                
                import org.apache.http.HttpResponse;
                import org.apache.http.NameValuePair;
                import org.apache.http.client.ClientProtocolException;
                import org.apache.http.client.HttpClient;
                import org.apache.http.client.entity.UrlEncodedFormEntity;
                import org.apache.http.client.methods.HttpPost;
                import org.apache.http.impl.client.DefaultHttpClient;
                import org.apache.http.message.BasicNameValuePair;
                
                import com.google.android.gcm.GCMRegistrar;
                import com.google.android.maps.MyLocationOverlay;
                
                import android.location.Location;
                import android.location.LocationListener;
                import android.location.LocationManager;
                import android.os.Bundle;
                import android.os.StrictMode;
                import android.util.Log;
                import android.view.View;
                import android.widget.Button;
                import android.widget.EditText;
                import android.widget.Toast;
                import android.app.Activity;
                import android.content.Context;
                
                public class Register extends Activity {
                
                
                
                
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_register);
                        final EditText email_id = (EditText)  findViewById(R.id.email_id) ;
                        final EditText name = (EditText) findViewById(R.id.name);
                        final EditText password = (EditText) findViewById(R.id.password);
                        Button button = (Button) findViewById(R.id.button1) ;
                
                
                
                        //generate GCM id
                        GCMRegistrar.checkDevice(this);
                        GCMRegistrar.checkManifest(this);
                        final String regId = GCMRegistrar.getRegistrationId(this);
                        if (regId.equals("")) {
                          GCMRegistrar.register(this, "12356");
                
                        } else {
                        String TAG = null;
                        Log.v(TAG, regId);
                
                        }
                        //generate GCM id ended
                        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                        StrictMode.setThreadPolicy(policy); 
                        //get current location
                
                        LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
                        LocationListener listner = new LocationListener() {
                
                            @Override
                            public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                                // TODO Auto-generated method stub
                
                            }
                
                            @Override
                            public void onProviderEnabled(String arg0) {
                                // TODO Auto-generated method stub
                
                            }
                
                            @Override
                            public void onProviderDisabled(String arg0) {
                                // TODO Auto-generated method stub
                
                            }
                
                            @Override
                            public void onLocationChanged(Location location) {
                                double myLonDouble = location.getLongitude();
                            final String myLon = Double.toString(myLonDouble);
                                double myLatDouble = location.getLatitude();
                                final String myLat = Double.toString(myLatDouble);
                
                            }
                        };
                        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listner);
                
                
                
                        //end get current location
                
                        button.setOnClickListener(new View.OnClickListener() {
                
                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        //postData();
                          HttpClient httpclient = new DefaultHttpClient();
                            HttpPost httppost = new HttpPost("http://xyz.com/folder/register.php");
                
                            try {
                                // Add your data
                                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                                nameValuePairs.add(new BasicNameValuePair("email", email_id.getText().toString()));
                                nameValuePairs.add(new BasicNameValuePair("name", name.getText().toString()));
                                nameValuePairs.add(new BasicNameValuePair("password", password.getText().toString()));
                                nameValuePairs.add(new BasicNameValuePair("regid", regId));
                                nameValuePairs.add(new BasicNameValuePair("uid", "2"));
                                nameValuePairs.add(new BasicNameValuePair("lat",myLat ));
                                nameValuePairs.add(new BasicNameValuePair("lon",myLon));
                               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                
                                // Execute HTTP Post Request
                               //Toast.makeText(this, resId, duration)
                                HttpResponse response = httpclient.execute(httppost);
                
                            } catch (ClientProtocolException e) {
                                // TODO Auto-generated catch block
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                            }
                
                    }
                });
                
                    }
                
                
                }
                

                推薦答案

                你應該好好學習一下 范圍和成員變量.問題是,您不能在一個方法中聲明一件事,然后嘗試從另一個方法訪問它.

                You should probably study up on scope and member variables. The thing is, you can't declare one thing in one method then attempt to access it from another method.

                所以,我們將那個東西聲明為成員變量,并在一個方法中定義它,然后它可以在另一個方法中使用.

                So, we declare that thing as a member variable, and define it in one method, then it can be used in another method.

                像這樣(我已經用 ** 標記了我的評論):

                Like so (I've marked my comments with **):

                public class Register extends Activity {
                
                    // "private" means it can only be accessed from this class
                    private String myLat = null; // ** Declare myLat
                    private String myLon = null; // ** Declare myLon
                
                
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_register);
                        final EditText email_id = (EditText)  findViewById(R.id.email_id) ;
                        final EditText name = (EditText) findViewById(R.id.name);
                        final EditText password = (EditText) findViewById(R.id.password);
                        Button button = (Button) findViewById(R.id.button1) ;
                
                
                
                        //generate GCM id
                        GCMRegistrar.checkDevice(this);
                        GCMRegistrar.checkManifest(this);
                        final String regId = GCMRegistrar.getRegistrationId(this);
                        if (regId.equals("")) {
                          GCMRegistrar.register(this, "12356");
                
                        } else {
                        String TAG = null;
                        Log.v(TAG, regId);
                
                        }
                        //generate GCM id ended
                        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                        StrictMode.setThreadPolicy(policy); 
                        //get current location
                
                        LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
                        LocationListener listner = new LocationListener() {
                
                            @Override
                            public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                                // TODO Auto-generated method stub
                
                            }
                
                            @Override
                            public void onProviderEnabled(String arg0) {
                                // TODO Auto-generated method stub
                
                            }
                
                            @Override
                            public void onProviderDisabled(String arg0) {
                                // TODO Auto-generated method stub
                
                            }
                
                            @Override
                            public void onLocationChanged(Location location) {
                                double myLonDouble = location.getLongitude();
                                myLon = Double.toString(myLonDouble); // ** Define myLon
                                double myLatDouble = location.getLatitude();
                                myLat = Double.toString(myLatDouble); // ** Define myLat
                
                            }
                        };
                        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listner);
                
                
                
                        //end get current location
                
                        button.setOnClickListener(new View.OnClickListener() {
                
                        @Override
                        public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        // ** Check if they have been defined
                        if (myLat == null || myLon == null)
                            return;
                
                        //postData();
                          HttpClient httpclient = new DefaultHttpClient();
                            HttpPost httppost = new HttpPost("http://xyz.com/folder/register.php");
                
                            try {
                            // Add your data
                            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                            nameValuePairs.add(new BasicNameValuePair("email", email_id.getText().toString()));
                            nameValuePairs.add(new BasicNameValuePair("name", name.getText().toString()));
                            nameValuePairs.add(new BasicNameValuePair("password", password.getText().toString()));
                            nameValuePairs.add(new BasicNameValuePair("regid", regId));
                            nameValuePairs.add(new BasicNameValuePair("uid", "2"));
                            nameValuePairs.add(new BasicNameValuePair("lat",myLat ));
                            nameValuePairs.add(new BasicNameValuePair("lon",myLon));
                               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                
                            // Execute HTTP Post Request
                               //Toast.makeText(this, resId, duration)
                            HttpResponse response = httpclient.execute(httppost);
                
                            } catch (ClientProtocolException e) {
                            // TODO Auto-generated catch block
                            } catch (IOException e) {
                            // TODO Auto-generated catch block
                            }
                
                        }
                    });
                
                    }
                
                
                }
                

                這篇關于從其他方法訪問變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  • <legend id='7H7Qi'><style id='7H7Qi'><dir id='7H7Qi'><q id='7H7Qi'></q></dir></style></legend>

                      <bdo id='7H7Qi'></bdo><ul id='7H7Qi'></ul>
                      <i id='7H7Qi'><tr id='7H7Qi'><dt id='7H7Qi'><q id='7H7Qi'><span id='7H7Qi'><b id='7H7Qi'><form id='7H7Qi'><ins id='7H7Qi'></ins><ul id='7H7Qi'></ul><sub id='7H7Qi'></sub></form><legend id='7H7Qi'></legend><bdo id='7H7Qi'><pre id='7H7Qi'><center id='7H7Qi'></center></pre></bdo></b><th id='7H7Qi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7H7Qi'><tfoot id='7H7Qi'></tfoot><dl id='7H7Qi'><fieldset id='7H7Qi'></fieldset></dl></div>
                    • <small id='7H7Qi'></small><noframes id='7H7Qi'>

                      <tfoot id='7H7Qi'></tfoot>
                        <tbody id='7H7Qi'></tbody>

                          主站蜘蛛池模板: 在线不卡视频 | 日韩欧美专区 | 伊人看片 | 亚洲国产精品视频一区 | 亚洲高清在线 | 国产91色在线 | 亚洲 | 久久久精品一区 | 天天激情综合 | 草草影院ccyy | 日本亚洲精品 | 午夜免费影视 | 超碰人人插 | 精品入口麻豆88视频 | 国产欧美综合在线 | 国产欧美日韩一区二区三区在线观看 | 久久国产精99精产国高潮 | 精品国产乱码久久久久久图片 | 一区二区三区高清在线观看 | 亚洲天堂久久 | 久久久久国产精品一区二区 | 日本a视频 | 日本黄色不卡视频 | 久久久久一区二区三区 | 人人干97| 中文在线播放 | 成人av高清 | 精品久久久久久 | 国产探花在线精品一区二区 | 欧美不卡| 国产一区二区在线看 | 污片在线免费观看 | 精品免费国产视频 | 成人在线| 精产国产伦理一二三区 | 91精品久久久久久久久久入口 | 精品伦精品一区二区三区视频 | 精品欧美激情精品一区 | 午夜小影院 | 一级毛片成人免费看a | 国产男女精品 | av在线一区二区三区 |