Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to fetch data in Spinner from api code

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 614
    Comment on it

    In the blelow code example I have clearly describe "how to fetch data from api server side"? for this first I have created activity_signup.xml layout here I have added TextView, ImageView, ScrollView, EditText, Spinner and Button. Now See Coding part here i have used ArrayList for SelectCountry, SelectProvince, SelectCity, SelectSuberb these all spinners objects, go through the below example to know how to fetch data in Spinner from api code.

     

    Step(1)signup_main.xml layout-
     

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@mipmap/background">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/signup"
            android:gravity="center"
            android:textSize="@dimen/text_large"
            android:textColor="@color/font_color"
            android:layout_marginTop="@dimen/margin_large"/>
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:src="@color/font_color"
            android:layout_marginTop="@dimen/margin_medium"
            />
    
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    
        android:paddingLeft="@dimen/margin_medium"
        android:paddingRight="@dimen/margin_medium"
        >
    
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/select_user_type"
            android:textSize="@dimen/text_large"
            android:textColor="@color/font_color"
            android:layout_marginTop="@dimen/margin_large"/>
    
        <!--Select user type layout-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/margin_medium"
            android:layout_marginLeft="@dimen/margin_xlarge"
            android:layout_marginRight="@dimen/text_xlarge"
            android:weightSum="2">
            <LinearLayout
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/radioButtonUser"
                    android:src="@mipmap/rediobtn_select"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/user"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textSize="@dimen/text_large"
                    android:textColor="@color/font_color"
                   />
            </LinearLayout>
            <LinearLayout
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/radioButtonBusinessUser"
                    android:src="@mipmap/rediobtn"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/business_user"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textSize="@dimen/text_large"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
        </LinearLayout>
        <!--End of select user type layout-->
    
    
        <!--Field layout -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="@dimen/margin_large"
            android:layout_marginLeft="@dimen/margin_medium"
            android:layout_marginRight="@dimen/text_medium"
            android:background="@drawable/login_bg">
    
            <!--Email address layout-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_margin="@dimen/margin_large">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/icon_mail"/>
                <EditText
                    android:id="@+id/emailAddressEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/email_address"
                    android:inputType="textEmailAddress"
                    android:textColorHint="@color/font_color"
                    android:background="#00000000"
                    android:textCursorDrawable="@drawable/custom_cursor_color"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
            <!--User name layout-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_margin="@dimen/margin_large">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/icon_user"/>
                <EditText
                    android:id="@+id/userNameEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/username"
                    android:inputType="text"
                    android:textColorHint="@color/font_color"
                    android:background="#00000000"
                    android:textCursorDrawable="@drawable/custom_cursor_color"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
            <!--Enter name and surname  layout-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_margin="@dimen/margin_large">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/icon_user"/>
                <EditText
                    android:id="@+id/userSurNameEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/enter_name_sirname"
                    android:inputType="text"
                    android:textColorHint="@color/font_color"
                    android:background="#00000000"
                    android:textCursorDrawable="@drawable/custom_cursor_color"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
            <!--Cell phone  layout-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_margin="@dimen/margin_large">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/icon_cell"/>
                <EditText
                    android:id="@+id/userCellPhoneEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/cell_phone_nuber"
                    android:inputType="phone"
                    android:textColorHint="@color/font_color"
                    android:background="#00000000"
                    android:textCursorDrawable="@drawable/custom_cursor_color"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
    
            <!--Select country   layout-->
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginLeft="@dimen/margin_large"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_small"
                android:layout_marginBottom="@dimen/margin_small">
    
                <ImageView
                    android:id="@+id/countryImageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:src="@mipmap/icon_country"/>
    
                <Spinner
                    android:layout_toRightOf="@+id/countryImageView"
                    android:id="@+id/country_spinner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    android:background="@android:color/transparent"
                    android:layout_centerVertical="true"/>
    
    
                <ImageView
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
            <!--Select province   layout-->
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginLeft="@dimen/margin_large"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_small"
                android:layout_marginBottom="@dimen/margin_small">
    
                <ImageView
                    android:id="@+id/provinceImageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:src="@mipmap/icon_country"/>
    
                <Spinner
                    android:layout_toRightOf="@+id/provinceImageView"
                    android:id="@+id/province_spinner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
    
                    android:inputType="text"
                    android:background="@android:color/transparent"
                    android:layout_centerVertical="true"/>
    
    
                <ImageView
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
    
            !--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
            <!--Select city   layout-->
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginLeft="@dimen/margin_large"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_small"
                android:layout_marginBottom="@dimen/margin_small">
    
                <ImageView
                    android:id="@+id/cityImageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:src="@mipmap/icon_country"/>
    
                <Spinner
                    android:layout_toRightOf="@+id/cityImageView"
                    android:id="@+id/city_spinner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
    
                    android:inputType="text"
                    android:background="@android:color/transparent"
                    android:layout_centerVertical="true"/>
    
    
                <ImageView
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
            !--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
            <!--Select city   layout-->
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginLeft="@dimen/margin_large"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_small"
                android:layout_marginBottom="@dimen/margin_small">
    
                <ImageView
                    android:id="@+id/suberbImageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:src="@mipmap/icon_country"/>
    
                <Spinner
                    android:layout_toRightOf="@+id/suberbImageView"
                    android:id="@+id/suberb_spinner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
    
                    android:inputType="text"
                    android:background="@android:color/transparent"
                    android:layout_centerVertical="true"/>
    
    
                <ImageView
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
            !--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
            <!-- &lt;!&ndash;Select country   layout&ndash;&gt;
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal"
                 android:layout_margin="@dimen/margin_large">
    
                 <ImageView
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:src="@mipmap/icon_country"/>
    
                 <Spinner
                     android:id="@+id/country_spinner"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:inputType="text" />
    
             </LinearLayout>
     -->
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
            <!--Password  layout-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_margin="@dimen/margin_large">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/icon_passwrod"/>
                <EditText
                    android:id="@+id/userPasswordEditText"
                    android:layout_width="match_parent"
    
                    android:layout_height="wrap_content"
                    android:hint="@string/enter_your_password"
                    android:inputType="textPassword"
                    android:textColorHint="@color/font_color"
                    android:background="#00000000"
                    android:textCursorDrawable="@drawable/custom_cursor_color"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
            <!--divider line -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/font_color">
    
            </LinearLayout>
    
    
            <!--Confirm Password  layout-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_margin="@dimen/margin_large">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/icon_passwrod"/>
                <EditText
                    android:id="@+id/userConfirmPasswordEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/confirm_password"
                    android:inputType="textPassword"
                    android:textColorHint="@color/font_color"
                    android:background="#00000000"
                    android:textCursorDrawable="@drawable/custom_cursor_color"
                    android:layout_marginLeft="@dimen/margin_medium"
                    android:textColor="@color/font_color"
                    />
            </LinearLayout>
    
    
    
        </LinearLayout>
    
        <!--Login button-->
        <Button
            android:id="@+id/signUpButton"
            android:layout_marginLeft="@dimen/margin_large"
            android:layout_marginRight="@dimen/margin_large"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_large"
            android:layout_marginBottom="@dimen/margin_large"
            android:background="@drawable/login_btn"
            android:text="@string/signup"
            android:textSize="@dimen/text_large"
            android:textColor="@color/font_color"/>
    
    
    </LinearLayout>
        </ScrollView>
    </LinearLayout>
    
    
    

    Step(2)SignUpActivity-
     

    public class  SignUpActivity extends ActionBarActivity implements View.OnClickListener,ActivityInterface ,AdapterView.OnItemSelectedListener {
    
        private ImageView radioButtonUser,radioButtonBusinessUser;
        private EditText userEmailEditText,userNameEditText,userSurNameEditText,cellNuberEditText,userPasswordEditText,userConfirmPasswordEditText;
        private Spinner countrySpinner,provinceSpinner,citySpinner,suberbSpinner;
        private Button singupButton;
    
        private String emailAddress,userName,userSurName,selectCountry,userCellPhone,userPassword,confirmPassword;
        private  int userType=0;
        private int selectedPosition;
        public static ArrayList<SelectCountry> selectCountriesList=new ArrayList<SelectCountry>();
        public ArrayList<SelectProvince> selectProvinceArrayList;
        public ArrayList<SelectCity> selectCityArrayList;
        public ArrayList<SelectSuberb> selectSuberbArrayList;
        private DataOffersArrayList dataOffers;
    
        private SelectCity selectCity;
        private SelectProvince selectProvince;
        private SelectSuberb selectSuberb;
        private String countryID=null, provinceID=null, cityID=null,superbID=null;
    
    
        private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
        public static final String EXTRA_MESSAGE = "message";
        private String SENDER_ID="1025757029424";
        public static final String PROPERTY_REG_ID = "registration_id";
        private static final String PROPERTY_APP_VERSION = "appVersion";
        private GoogleCloudMessaging gcm;
        private Context context;
        private String regid;
        private Dialog dialog;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    
            setContentView(R.layout.activity_signup);
    
            /* Google cloud messaging */
            context = getApplicationContext();
            if (checkPlayServices()) {
                gcm = GoogleCloudMessaging.getInstance(this);
                regid = getRegistrationId(context);
                MyUtility.showLog("regID.....",regid);
                registerInBackground();
            }
    
            //Initialize UI
            intializeUI();
            // Intialize spinner firs hint values
            intializeSpinnerHintValues();
    
            // fetch country name and code from server side
            fetchCountryItems();
        }
    
        /**
         * This function fetching country items as name and code when first activity open
         *
         */
        private void fetchCountryItems() {
    
            if (MyUtility.isConnected(this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_COUNTRY, Constsants.SELECT_COUNTRY));
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(this, ServerUrl.BASE_URL+ServerUrl.SELECT_COUNTRY_API, nameValuePairs, Constsants.SELECT_COUNTRY_API_CODE,this);
                lineDataServiceTask.execute();
            }else
            {
                Toast.makeText(this,getResources().getString(R.string.internet_connectivity_msg),Toast.LENGTH_SHORT).show();
            }
        }
    
    
        // Intialize UI ID'S
        public void intializeUI(){
    
    
            dataOffers=DataOffersArrayList.getInstance();
            selectProvinceArrayList=dataOffers.getProvinceArrayList();
            selectCityArrayList=dataOffers.getCityArrayList();
            selectSuberbArrayList=dataOffers.getSuberbArrayList();
    
    
            radioButtonUser=(ImageView)findViewById(R.id.radioButtonUser);
            radioButtonUser.setOnClickListener(this);
            radioButtonBusinessUser=(ImageView)findViewById(R.id.radioButtonBusinessUser);
            radioButtonBusinessUser.setOnClickListener(this);
    
            singupButton=(Button)findViewById(R.id.signUpButton);
            singupButton.setOnClickListener(this);
    
            userEmailEditText=(EditText)findViewById(R.id.emailAddressEditText);
            userNameEditText=(EditText)findViewById(R.id.userNameEditText);
            userSurNameEditText=(EditText)findViewById(R.id.userSurNameEditText);
            cellNuberEditText=(EditText)findViewById(R.id.userCellPhoneEditText);
    
            countrySpinner=(Spinner)findViewById(R.id.country_spinner);
            citySpinner=(Spinner)findViewById(R.id.city_spinner);
            provinceSpinner=(Spinner)findViewById(R.id.province_spinner);
            suberbSpinner=(Spinner)findViewById(R.id.suberb_spinner);
    
            // Set here selected item listener to all spinners
            citySpinner.setOnItemSelectedListener(this);
            provinceSpinner.setOnItemSelectedListener(this);
            suberbSpinner.setOnItemSelectedListener(this);
            countrySpinner.setOnItemSelectedListener(this);
    
    
            userPasswordEditText=(EditText)findViewById(R.id.userPasswordEditText);
            userConfirmPasswordEditText=(EditText)findViewById(R.id.userConfirmPasswordEditText);
    
    
        }
    
    
        // intialize all spiner with intial values
        private void intializeSpinnerHintValues() {
    
    
            selectProvinceArrayList.clear();
            selectProvince = new SelectProvince();
            selectProvince.setProvinceName("Select Province");
            selectProvince.setProvinceID("0");
            selectProvinceArrayList.add(selectProvince);
            provinceSpinner.setAdapter(new ProvinceAdapter(selectProvinceArrayList, this));
    
            selectCityArrayList.clear();
            selectCity = new SelectCity();
            selectCity.setCityName("Select City");
            selectCity.setCityID("0");
            selectCityArrayList.add(selectCity);
            citySpinner.setAdapter(new CityAdapter(selectCityArrayList, this));
    
    
            selectSuberbArrayList.clear();
            selectSuberb = new SelectSuberb();
            selectSuberb.setSuberbName("Select Suberb");
            selectSuberb.setSuberbID("0");
            selectSuberbArrayList.add(selectSuberb);
            suberbSpinner.setAdapter(new SuberbAdapter(selectSuberbArrayList, this));
    
        }
    
        @Override
        public void onSuccess(int apiCode) {
            if(apiCode==Constsants.SELECT_COUNTRY_API_CODE){
               // Toast.makeText(this,"fetch list successfully", Toast.LENGTH_SHORT).show();
                //set adapter to spinner
                countrySpinner.setAdapter(new BrandAdapter(selectCountriesList));
    
    
            }
            if(apiCode==Constsants.SIGN_UP_API_CODE){
                 if(SharedPreferenceManager.getInstance().getUserDetails(this,Constsants.RESPONSE_USER_TYPE).equals("0")) {
                   //  Toast.makeText(this, "Registered successfully", Toast.LENGTH_SHORT).show();
                     Intent intent = new Intent(SignUpActivity.this, SelectLocationActivity.class);
                     intent.putExtra("activity","signup");
                     startActivity(intent);
                 }else {
                     Intent intent=new Intent(SignUpActivity.this, ActivityAddBusiness.class);
                     startActivity(intent);
                 }
    
            }
            if(provinceID.isEmpty()|| provinceSpinner==null)
    
            if(apiCode==Constsants.SELECT_CITY_API_CODE){
                selectCityArrayList=DataOffersArrayList.getInstance().getCityArrayList();
                citySpinner.setAdapter(new CityAdapter(selectCityArrayList,this));
            }
            if(apiCode==Constsants.SELECT_PROVINCE_API_CODE){
                selectProvinceArrayList=DataOffersArrayList.getInstance().getProvinceArrayList();
                provinceSpinner.setAdapter(new ProvinceAdapter(selectProvinceArrayList,this));
            }
            if(apiCode==Constsants.SELECT_SUBERB_API_CODE){
                selectSuberbArrayList=DataOffersArrayList.getInstance().getSuberbArrayList();
                MyUtility.showLog("SUBERB ARRAY LIST SIZE ",selectSuberbArrayList.size()+"");
                suberbSpinner.setAdapter(new SuberbAdapter(selectSuberbArrayList, this));
            }
    
        }
    
        @Override
        public void onFailed(int apiCode, String response) {
            if(apiCode==Constsants.SIGN_UP_API_CODE) {
    
                showDialogWithSuccessfull("Username Already exists and duplicate account is not permitted");
    
            }
            if(apiCode==Constsants.SELECT_COUNTRY_API_CODE){
                countrySpinner.setAdapter(new BrandAdapter(selectCountriesList));
            }
        }
    
        @Override
        public void onClick(View v) {
    
            switch (v.getId()){
                case R.id.radioButtonUser :
                    MyUtility.showLog("click radion button user", "ok");
    
                    if(userType==0){
    
                    }else{
                        userType=0;
                        radioButtonUser.setImageResource(R.mipmap.rediobtn_select);
                        radioButtonBusinessUser.setImageResource(R.mipmap.rediobtn);
                    }
    
    
                    break;
                case R.id.radioButtonBusinessUser :
                    MyUtility.showLog("click radion button busines user", "ok");
    
                       if(userType==1){
    
                       }else{
                           MyUtility.showLog("user type is one ",userType+"");
                           userType=1;
                           radioButtonUser.setImageResource(R.mipmap.rediobtn);
                           radioButtonBusinessUser.setImageResource(R.mipmap.rediobtn_select);
                       }
    
                    break;
                case R.id.signUpButton :
                    // do something
    
                        boolean isValid=validateInput();
                    if(isValid) {
                        // check internet connectivity availability before run to API
                        if (MyUtility.isConnected(this)) {
    
                            registerUser();// this method run to API which register user
    
                        } else {
                            Toast.makeText(this, getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
                            finish();
                        }
                    }
    
                    break;
            }
    
        }
    
    
    
        /**
         * to validate input text fields
         */
        boolean validateInput() {
            EmailValidator emailValidator = new EmailValidator();
    
            emailAddress=userEmailEditText.getText().toString().trim();
            userName=userNameEditText.getText().toString().trim();
            userSurName=userSurNameEditText.getText().toString().trim();
            userCellPhone=cellNuberEditText.getText().toString().trim();
            MyUtility.showLog("USER CELL NUMBER ",userCellPhone);
            selectCountry=selectCountriesList.get(selectedPosition).getCountryCode().toString().trim();
            userPassword=userPasswordEditText.getText().toString().trim();
            confirmPassword=userConfirmPasswordEditText.getText().toString().trim();
    
            if (!emailValidator.validate(emailAddress)) {
                userEmailEditText.setError("Please enter a valid email");
                userEmailEditText.requestFocus();
                return false;
            }
    
            if(userName.equals("")){
                userNameEditText.setError("Please enter  name");
                userNameEditText.requestFocus();
                return false;
            }
    
            if(userSurName.equals("")){
                userSurNameEditText.setError("Please enter  surname");
                userSurNameEditText.requestFocus();
                return false;
            }
    
            if(userCellPhone.equals("")){
                cellNuberEditText.setError("Please enter  cell phone number");
                cellNuberEditText.requestFocus();
                return false;
            }
    
            if(countryID.equals("null")){
                Toast.makeText(this,"Select Country",Toast.LENGTH_SHORT).show();
                return  false;
                //((TextView)countrySpinner.getSelectedView()).setError("Select a country ");
            }
    
    
    
            if(provinceID.equals("0") || provinceID.equals("null")){
                Toast.makeText(this,"Select Province",Toast.LENGTH_SHORT).show();
                return false;
                //((TextView)provinceSpinner.getSelectedView()).setError("Select province ");
            }
    
    
            if(cityID.equals("0") || cityID.equals("null")){
                Toast.makeText(this,"Select City",Toast.LENGTH_SHORT).show();
                return false;
                //((TextView)citySpinner.getSelectedView()).setError("Select city ");
            }
    
            if(superbID.equals("0") || superbID.equals("null")){
                Toast.makeText(this,"Select Superb",Toast.LENGTH_SHORT).show();
                return  false;
                //((TextView)suberbSpinner.getSelectedView()).setError("Select superb");
            }
    
            else if (userPassword.equals("")) {
                userPasswordEditText.setError("Please enter a valid password");
                userPasswordEditText.requestFocus();
                return false;
    
            }
            else if (userPassword.length()<6) {
                userPasswordEditText.setError("Password length must be 6 digit");
                userPasswordEditText.requestFocus();
                return false;
    
            }
    
            else if (!userPassword.equals(userConfirmPasswordEditText.getText()
                    .toString())) {
                userConfirmPasswordEditText.setError("Passwords do not match");
                userConfirmPasswordEditText.requestFocus();
                return false;
            }
    
            return true;
        }
    
        // run api
        private void registerUser() {
    
    
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_REGISTER, Constsants.USER_REGISTER));
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_EMAIL_ID,emailAddress));
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_NAME,userName));
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_FIRST_NAME,userSurName));
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_COUNTRY,selectCountry));
            nameValuePairs.add(new BasicNameValuePair(Constsants.SIGNUP_CITYID,cityID));
            nameValuePairs.add(new BasicNameValuePair(Constsants.SIGNUP_PROVICEID,provinceID));
            nameValuePairs.add(new BasicNameValuePair(Constsants.SIGNUP_SUBERBID,superbID));
            nameValuePairs.add(new BasicNameValuePair(Constsants.REGISTRATION_ID,regid));
            nameValuePairs.add(new BasicNameValuePair(Constsants.DEVICE_TYPE,"android"));
    
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_PASSWORD,userPassword));
            MyUtility.showLog("cell number registered ........",userCellPhone);
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_CELL_PHONE,userCellPhone));
            nameValuePairs.add(new BasicNameValuePair(Constsants.USER_TYPE,String.valueOf(userType)));
            WebServiceTask lineDataServiceTask =
                    new WebServiceTask(this, ServerUrl.BASE_URL+ServerUrl.SIGN_UP_API, nameValuePairs, Constsants.SIGN_UP_API_CODE,this);
            lineDataServiceTask.execute();
    
        }
    
        // this method fetch province category's items from server based on selected id
        private void fetchProviceItems(String countryID) {
    
            MyUtility.showLog("Country Id########### ",countryID);
    
            if (MyUtility.isConnected(SignUpActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_PROVINCE_SIGNUP, Constsants.SELECT_PROVINCE_SIGNUP));
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_CITY_SIGNUP, Constsants.SELECT_CITY_SIGNUP));
                nameValuePairs.add(new BasicNameValuePair(Constsants.COUNTRY_ID, countryID));
    
    
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SignUpActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_PROVINCE_API, nameValuePairs, Constsants.SELECT_PROVINCE_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SignUpActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
    
        // this method fetch city category's items from server based on selected id
        private void fetchCityItems(String provinceID) {
    
            MyUtility.showLog("Province Id######### ",provinceID);
            MyUtility.showLog("Country Id######### ",countryID);
    
    
            if (MyUtility.isConnected(SignUpActivity.this)) {
    
    
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_CITY_SIGNUP, Constsants.SELECT_CITY_SIGNUP));
                nameValuePairs.add(new BasicNameValuePair(Constsants.PROVINCE_ID, provinceID));
                nameValuePairs.add(new BasicNameValuePair(Constsants.COUNTRY_ID, countryID));
    
    
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SignUpActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_CITY_API, nameValuePairs, Constsants.SELECT_CITY_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SignUpActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
    
        private void fetchSuberbItems(String cityID) {
    
            if (MyUtility.isConnected(SignUpActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_SUBERB_SIGNUP, Constsants.SELECT_SUBERB_SIGNUP));
                nameValuePairs.add(new BasicNameValuePair(Constsants.CITY_ID, cityID));
                WebServiceTask lineDataServiceTask =new WebServiceTask(SignUpActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_SUBERB_API, nameValuePairs, Constsants.SELECT_SUBERB_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SignUpActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
    
    
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
                if(parent.getId() == countrySpinner.getId()) {
                    countryID = SignUpActivity.selectCountriesList.get(position).getCountryCode();
                   // MyUtility.showLog("selcted country id ",countryID+"");
                    // Fetch the province items list from server by hit the api
                    if (countryID.equals("0") || countryID.equals("null")) {
                       // MyUtility.showLog("countryID id null ", countryID + "");
                    } else {
                        MyUtility.showLog("calling fetch province method here ",countryID+"");
                        fetchProviceItems(countryID);
                    }
    
                }
              else  if (parent.getId() == provinceSpinner.getId()) {
    
    
                    provinceID = selectProvinceArrayList.get(position).getProvinceID();
                    MyUtility.showLog("selcted province  id ",provinceID+"");
                    // Fetch the city items from server by the hit api
                    MyUtility.showLog("SIZE OF PROVINCE ARRAY LIST ",selectProvinceArrayList.size()+"");
    
                    if (provinceID.equals("0") || provinceID.equals("null")) {
    
    
                    } else {
                        fetchCityItems(provinceID);
                    }
    
                }
    
              else  if (parent.getId() ==citySpinner.getId()) {
    
                    cityID = selectCityArrayList.get(position).getCityID();
                    // Fetch the category items from server by the hit api
    
                    System.out.println("select city items");
                    if (cityID.equals("null") || cityID.equals("0") ) {
                        //fetchCityItems(provinceID);
                    } else {
                        fetchSuberbItems(cityID);
                    }
    
                }
               else if(parent.getId() == suberbSpinner.getId()) {
    
                    superbID = selectSuberbArrayList.get(position).getSuberbID();
                    MyUtility.showLog("sub urb id ", superbID);
                }
        }

     

 0 Comment(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: