Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Get the Customer Value as Null in An Android App?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 594
    Answer it

    Here is my code

    public class NewAddressActivity extends BaseActivity {
    
        private RobotoEditText houseNumber, fullName, phoneNumber, alternateNumber;
    
        private RobotoEditText  region;
    
        private RobotoEditText landMark, town, pinCode;
    
        private Address address;
    
        public Customer customer;
    
        public Order order;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.new_address);
    
            ActionBarUtils.setActionBar(this, true);
    
            getActiveActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
    
            this.setTitle("Add New Address");
    
            fullName = (RobotoEditText) findViewById(R.id.name);
    
            town = (RobotoEditText) findViewById(R.id.town);
    
            phoneNumber = (RobotoEditText) findViewById(R.id.mobile_number);
    
            alternateNumber = (RobotoEditText) findViewById(R.id.alternate_number);//alternate number
    
            houseNumber = (RobotoEditText) findViewById(R.id.house_name);
    
            landMark = (RobotoEditText) findViewById(R.id.land_mark);
    
            region = (RobotoEditText) findViewById(R.id.street_name);
    
            pinCode = (RobotoEditText) findViewById(R.id.pin_number);
    
            Button submit = (Button) findViewById(R.id.submit_address);
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    sendAddress();
                }
            });
    
            updateView();
    
        }
    
        private void updateView() {
    
            //Address address = Order.getInstance().getAddress();
    
            if(address != null) {
    
                fullName.setText(address.getFullName());
                phoneNumber.setText(address.getMobileNumber());
                pinCode.setText(address.getPincode());
                houseNumber.setText(address.getHouseNumber());
                landMark.setText(address.getLandMark());
                region.setText(address.getRegion());
                town.setText(address.getAddress());
            } else{
    
                if(Order.getInstance().getCustomer() != null) {
                    fullName.setText(Order.getInstance().getCustomer().getFullName());
    
    
                }
            }
        }
    
        private void sendAddress(){
    
            AddNewAddressApi request = new AddNewAddressApi(listener);
    
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("AddressID",0);
    
    
                   // jsonObject.put("CustomerID",Order.getInstance().getCustomer().getId());
    
    
                    jsonObject.put("CustomerID",Order.getInstance().getCustomer().getId());
    
    
                jsonObject.put("FullName",fullName.getText().toString());
                jsonObject.put("Address",town.getText().toString());
                jsonObject.put("ContactNumber",phoneNumber.getText().toString());
                jsonObject.put("Pincode",pinCode.getText().toString());
                jsonObject.put("HouseNumber",houseNumber.getText().toString());
                jsonObject.put("LandMark",landMark.getText().toString());
                jsonObject.put("AddressType","Home");
                jsonObject.put("Region",region.getText().toString());
    
    
                Address address = new Address(jsonObject);
              //Order.getInstance().setAddress(address);
            } catch (JSONException e) {
                e.printStackTrace();
            }
    
            jsonArray.put(jsonObject);
            //request.addParam("");
            request.addParam("address",jsonArray);
    
            request.fire();
    
            showProgressWheel();
        }
    
    
        RPCRequest.OnResponseListener listener = new RPCRequest.OnResponseListener<AddNewAddressApi>() {
            @Override
            public void onSuccessResponse(RPCRequest request, AddNewAddressApi response) {
    
                hideProgressWheel(true);
    
                Address address = new Address();
                address.setId(response.AddressID);
    
    
                address.setMobileNumber(phoneNumber.getText().toString());
                try {
                    address.setAlternateNumber(alternateNumber.getText().toString());
                }catch (NullPointerException e){
    
                }
                address.setAddress(town.getText().toString());
                address.setPincode(pinCode.getText().toString());
                address.setFullName(fullName.getText().toString());
                address.setHouseNumber(houseNumber.getText().toString());
                address.setStreet(region.getText().toString());
                address.setLandMark(landMark.getText().toString());
                //Order.getInstance().setAddress(address);
    
              if(Order.getInstance().getOrderId() == null) {
    
                  Intent intent = new Intent(NewAddressActivity.this, HomeScreenActivity.class);
    
                   startActivity(intent);
               }else {
                    finish();
                }
    
            }
    
            @Override
            public void onErrorResponse(RPCRequest request, ResponseError error) {
    
                hideProgressWheel(true);
    
                showErrorMessage(error.getErrorTitle(), error.getErrorSummary());
    
            }
        };
    
        private void showErrorMessage(String title, String message) {
            AlertDialog.Builder builder = new AlertDialog.Builder(NewAddressActivity.this);
    
            builder.setMessage(message)
                    .setTitle(title);
    
            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int i) {
                    dialog.dismiss();
                }
            });
    
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    
    
    }
    

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: