Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create change location page in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 159
    Comment on it

    In the below example code I have created change location page. Here I have first created select_location.xml layout. In select_location layout I have added ScollView , TextView and imageView and In Selectlocation.Activity I have intializeUI value and I have used api code from backend server for fetching value data and I have also used onClicklistner method. See the below code it will clerly describe you how to make change locationpage.

    Step(1)created select_location.xml layout

    <?xml version="1.0" encoding="utf-8"?>
    
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/background">
    
    
        <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_country"
                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"
                />
    
    
            <!--Select country   layout-->
            <RelativeLayout
                android:id="@+id/spinnercountry_layout"
                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:background="@drawable/login_bg"
                android:padding="1dp"
                android:layout_marginTop="@dimen/margin_xlarge"
                >
                <TextView
    
                    android:id="@+id/country_spinner"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    android:textColor="@color/font_color"
                    android:textSize="@dimen/text_large"
                    android:text="@string/select_country"
                    android:layout_marginLeft="@dimen/margin_medium"
                    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:paddingRight="@dimen/margin_medium"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
    
            <!--Select province spinner layoyut-->
            <RelativeLayout
                android:id="@+id/spinnerprovince_layout"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:background="@drawable/login_bg"
                android:layout_marginLeft="@dimen/margin_large"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_medium"
                android:padding="1dp"
                >
                <TextView
                     android:id="@+id/province_spinner"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    android:textColor="@color/font_color"
                    android:textSize="@dimen/text_large"
                    android:text="@string/select_province"
                    android:layout_marginLeft="@dimen/margin_medium"
                    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:paddingRight="@dimen/margin_medium"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
    
            <!--Select city spinner layoyut-->
            <RelativeLayout
                android:id="@+id/spinnercity_layout"
                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:background="@drawable/login_bg"
                android:layout_marginTop="@dimen/margin_medium"
                android:padding="1dp"
                >
                <TextView
    
                    android:id="@+id/city_spinner"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    android:textColor="@color/font_color"
                    android:textSize="@dimen/text_large"
                    android:text="@string/select_city"
                    android:layout_marginLeft="@dimen/margin_medium"
                    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:paddingRight="@dimen/margin_medium"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
            <!--Select suberb spinner layoyut-->
            <RelativeLayout
    
                android:id="@+id/spinnersuberb_layout"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginLeft="@dimen/margin_large"
                android:background="@drawable/login_bg"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_medium"
                android:padding="1dp"
                >
                <TextView
    
                    android:id="@+id/suberb_spinner"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    android:textColor="@color/font_color"
                    android:textSize="@dimen/text_large"
                    android:text="@string/select_suberb"
                    android:layout_marginLeft="@dimen/margin_medium"
                    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:paddingRight="@dimen/margin_medium"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
    
    
    
            <RelativeLayout
    
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:layout_marginLeft="@dimen/margin_large"
                android:background="@drawable/login_bg"
                android:layout_marginRight="@dimen/margin_large"
                android:layout_marginTop="@dimen/margin_medium"
                android:padding="1dp"
                >
    
    
    
    
    
                <!--Select category spinner layoyut11111111-->
                <RelativeLayout
                    android:id="@+id/spinnercat_layout1"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:orientation="horizontal"
                    android:gravity="center_vertical"
                    android:padding="12dp"
                    android:visibility="gone">
                    <TextView
    
                        android:id="@+id/selectcat_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/select_category"
                        android:textSize="@dimen/text_large"
                        android:textColor="@color/font_color"
                        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:paddingRight="@dimen/margin_medium"
                        android:src="@mipmap/icon_drop_down"/>
    
                </RelativeLayout>
                <!--End of layout 11111111111111-->
    
                <!--Select suberb spinner layoyut-->
                <RelativeLayout
    
                    android:id="@+id/spinnercategory_layout2"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:orientation="horizontal"
                    android:padding="1dp"
                    android:visibility="visible"
                    >
                    <TextView
    
                        android:id="@+id/spinnerCategory"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:inputType="text"
                        android:textColor="@color/font_color"
                        android:textSize="@dimen/text_large"
                        android:text="@string/select_category"
                        android:layout_marginLeft="@dimen/margin_medium"
                        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:paddingRight="@dimen/margin_medium"
                        android:src="@mipmap/icon_drop_down"/>
    
                </RelativeLayout>
    
            </RelativeLayout>
            <!-- rajshekhar -->
            <RelativeLayout
    
                android:id="@+id/spinnercategory_layout3"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:padding="1dp"
                android:layout_marginLeft="@dimen/margin_large"
                android:layout_marginRight="@dimen/margin_large"
                android:background="@drawable/login_bg"
                android:layout_marginTop="@dimen/margin_medium"
                android:layout_below="@+id/spinnercategory_layout2"
                android:visibility="visible"
                >
                <TextView
    
                    android:id="@+id/selectItem"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    android:textColor="@color/font_color"
                    android:textSize="@dimen/text_large"
                    android:text="@string/select_sub_category"
                    android:layout_marginLeft="@dimen/margin_medium"
                    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:paddingRight="@dimen/margin_medium"
                    android:src="@mipmap/icon_drop_down"/>
    
            </RelativeLayout>
    
            <!--Login button-->
            <Button
                android:id="@+id/nextButton"
                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="40dp"
                android:background="@drawable/login_btn"
                android:text="@string/next"
                android:textSize="@dimen/text_large"
                android:textColor="@color/font_color"/>
    
    
    
        </LinearLayout>
    </ScrollView>
    

    Step(2)-Created a new SelectLocationActivity-

    public class SelectLocationActivity extends ActionBarActivity implements ActivityInterface,View.OnClickListener{
        private RelativeLayout layoutCountry,layoutProvince,layoutCity,layoutSuberb,layoutCategory,layoutCategorySub;
        private String countryID="", provinceID="", cityID="",suberbID="",categoryID="",categorySubID="";
        private TextView countryTextView,provinceTextView,cityTextView,suberbTextView,categoryTextView,categorySubTextView;
        private Button nextButton;
        private String str;
        private int dialogID;
        private  SharedPreferenceManager sharedPreferenceManager;
        private  AlertDialog helpDialog;
       // public static ArrayList<SelectCity> cityArrayList ;
        public static ArrayList<SelectCountry> countryArrayList;
       // public static ArrayList<SelectProvince> provinceArrayList ;
        //public static ArrayList<SelectCategory> categoryArrayList ;
       // public static ArrayList<SelectSuberb> suberbArrayList ;
        private ArrayList<GetLocationData> getLocationDataArrayList;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_select_location);
    
            intializeUI();
            fetchSelectedLocation();
    
    
        }
    
        private void intializeUI() {
            sharedPreferenceManager = SharedPreferenceManager.getInstance();
    
            layoutCountry=(RelativeLayout)findViewById(R.id.spinnercountry_layout);
            layoutCountry.setOnClickListener(this);
    
            layoutProvince=(RelativeLayout)findViewById(R.id.spinnerprovince_layout);
            layoutProvince.setOnClickListener(this);
    
            layoutCity=(RelativeLayout)findViewById(R.id.spinnercity_layout);
            layoutCity.setOnClickListener(this);
    
            layoutSuberb=(RelativeLayout)findViewById(R.id.spinnersuberb_layout);
            layoutSuberb.setOnClickListener(this);
    
            layoutCategory=(RelativeLayout)findViewById(R.id.spinnercategory_layout2);
            layoutCategory.setOnClickListener(this);
    
            //rajshekhar
            layoutCategorySub=(RelativeLayout)findViewById(R.id.spinnercategory_layout3);
            layoutCategorySub.setOnClickListener(this);
    
    
    
    
            // get textview ids
            countryTextView=(TextView)findViewById(R.id.country_spinner);
            provinceTextView=(TextView)findViewById(R.id.province_spinner);
            cityTextView=(TextView)findViewById(R.id.city_spinner);
            suberbTextView=(TextView)findViewById(R.id.suberb_spinner);
            categoryTextView=(TextView)findViewById(R.id.spinnerCategory);
            //rajshekhar
            categorySubTextView=(TextView)findViewById(R.id.selectItem);
    
            nextButton=(Button)findViewById(R.id.nextButton);
            nextButton.setOnClickListener(this);
    
    
        }
    
         private void fetchSelectedLocation() {// fetch last selected location values
            if (MyUtility.isConnected(SelectLocationActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.GET_LOCATION, Constsants.GET_LOCATION));
                nameValuePairs.add(new BasicNameValuePair(Constsants.USER_ID, SharedPreferenceManager.getInstance().getUserDetails(SelectLocationActivity.this,Constsants.RESPONSE_USER_ID)));
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SelectLocationActivity.this, ServerUrl.BASE_URL + ServerUrl.GET_LOCATION_API, nameValuePairs, Constsants.GET_LOCATION_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SelectLocationActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
    
        // Fetch country items from server
        private void fetchCountryList() {
            if (MyUtility.isConnected(this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.COUNTRY_SELECT, Constsants.COUNTRY_SELECT));
                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();
            }
        }
    
        // this method fetch province category's items from server based on selected id
        private void fetchProviceItems() {
    
            if (MyUtility.isConnected(SelectLocationActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.PROVINCE_SELECT, Constsants.PROVINCE_SELECT));
                nameValuePairs.add(new BasicNameValuePair(Constsants.COUNTRY_ID, countryID));
    
    
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SelectLocationActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_PROVINCE_API, nameValuePairs, Constsants.SELECT_PROVINCE_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SelectLocationActivity.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() {
    
            if (MyUtility.isConnected(SelectLocationActivity.this)) {
             ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.CITY_SELECT, Constsants.CITY_SELECT));
                nameValuePairs.add(new BasicNameValuePair(Constsants.PROVINCE_ID, provinceID));
    
    
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SelectLocationActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_CITY_API, nameValuePairs, Constsants.SELECT_CITY_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SelectLocationActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
    
        private void intialilzeCategorySpinner() {
            if (MyUtility.isConnected(SelectLocationActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_CATEGORY, Constsants.SELECT_CATEGORY));
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SelectLocationActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_CATEGORY_API, nameValuePairs, Constsants.SELECT_CATEGORY_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SelectLocationActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
    
    
        private void fetchSuberbItems() {
            if (MyUtility.isConnected(SelectLocationActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SUBERB_SELECT, Constsants.SUBERB_SELECT));
                nameValuePairs.add(new BasicNameValuePair(Constsants.CITY_ID, cityID));
    
    
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SelectLocationActivity.this, ServerUrl.BASE_URL + ServerUrl.SELECT_SUBERB_API, nameValuePairs, Constsants.SELECT_SUBERB_API_CODE,this);
                lineDataServiceTask.execute();
            } else {
                Toast.makeText(SelectLocationActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
        }
        @Override
        public void onSuccess(int apiCode) {
            if(apiCode==Constsants.GET_LOCATION_API_CODE) {
                getLocationDataArrayList = DataOffersArrayList.getInstance().getGetLocationDataArrayList();
                countryTextView.setText(getLocationDataArrayList.get(0).getName());
                provinceTextView.setText(getLocationDataArrayList.get(1).getName());
                cityTextView.setText(getLocationDataArrayList.get(2).getName());
                suberbTextView.setText(getLocationDataArrayList.get(3).getName());
                categoryTextView.setText(getLocationDataArrayList.get(4).getCategoryName());
    
                countryID=getLocationDataArrayList.get(0).getId();
                provinceID=getLocationDataArrayList.get(1).getId();
                cityID=getLocationDataArrayList.get(2).getId();
                suberbID=getLocationDataArrayList.get(3).getId();
                categoryID=getLocationDataArrayList.get(4).getId();
    
    
    
            }
    
    
            if(apiCode==Constsants.SECOND_SIGNUP_API_CODE) {
    
                    Intent intent = new Intent(SelectLocationActivity.this, ViewOffersActivity.class);
                    intent.putExtra("callX", true);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
    
            }
    
            if(apiCode==Constsants.SELECT_COUNTRY_API_CODE){
               countryArrayList=DataOffersArrayList.getInstance().getSelectCountriesList();
                popupDialog(countryArrayList);
    
    
            }
            if(apiCode==Constsants.SELECT_PROVINCE_API_CODE){
                countryArrayList=DataOffersArrayList.getInstance().getSelectCountriesList();
                popupDialog(countryArrayList);
    
    
            }
            if(apiCode==Constsants.SELECT_CITY_API_CODE){
                countryArrayList=DataOffersArrayList.getInstance().getSelectCountriesList();
                popupDialog(countryArrayList);
    
    
            }
            if(apiCode==Constsants.SELECT_SUBERB_API_CODE){
                countryArrayList=DataOffersArrayList.getInstance().getSelectCountriesList();
                popupDialog(countryArrayList);
    
    
            }
            if(apiCode==Constsants.SELECT_CATEGORY_API_CODE){
                countryArrayList=DataOffersArrayList.getInstance().getSelectCountriesList();
                popupDialog(countryArrayList);
            }
        }
    
        @Override
        public void onFailed(int apiCode, String response) {
    
        }
    
        @Override
        public void onClick(View v) {
    
            if(v.getId()==nextButton.getId()) {
    
                MyUtility.showLog("Category id",categoryID);
                if (countryID.equals("")) {
                    str = "Please select country ";
                    Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    
                }
               else if (provinceID.equals("")) {
                    str = "Please select province";
                    Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    
                }
                else if (cityID.equals("")) {
                    str = "Please select city ";
                    Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    
                }
               else if (suberbID.equals("")) {
                    str = "Please select suberb";
                   Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
                }
                else if (categoryID.equals("") || categoryID.equals("0")) {
                    str = "Please select category";
                    Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
                }
    
                // rajshekhar
    
                else if(categorySubID.equals("")||categorySubID.equals("0")){
                     str ="Please select Sub category";
                    Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
    
                }
                else {
                    signUpUser();
                }
            }// close next button id if condition
    
    
            if(v.getId()==layoutCountry.getId()){
                MyUtility.showLog("click country layout","......");
                dialogID=0;
                provinceTextView.setText("Select Province");
                cityTextView.setText("Select City");
                suberbTextView.setText("Select Suberb");
    
                // change color of text view
                provinceTextView.setTextColor(Color.BLACK);
                cityTextView.setTextColor(Color.BLACK);
                suberbTextView.setTextColor(Color.BLACK);
    
               // change text view id
                provinceID="";
                cityID="";
                suberbID="";
                fetchCountryList();
              //  popupDialog(countryArrayList);
    
    
            }
    
            if(v.getId()==layoutProvince.getId()){
                MyUtility.showLog("click city layout","......");
                dialogID=1;
                cityTextView.setText("Select city");
                suberbTextView.setText("Select Suberb");
                cityTextView.setTextColor(Color.BLACK);
                suberbTextView.setTextColor(Color.BLACK);
                cityID="";
                suberbID="";
                fetchProviceItems();
    
            }
    
            if(v.getId()==layoutCity.getId()){
                MyUtility.showLog("click city layout","......");
                dialogID=2;
                suberbTextView.setText("Select Suberb");
    
                // change color of text view
                suberbTextView.setTextColor(Color.BLACK);
                // change text view id
                suberbID="";
                fetchCityItems();
               // popupDialog(countryArrayList);
    
    
            }
    
            if(v.getId()==layoutSuberb.getId()){
    
                dialogID=3;
                fetchSuberbItems();
                //popupDialog(countryArrayList);
    
    
            }
            if(v.getId()==layoutCategory.getId()){
    
                dialogID=4;
                intialilzeCategorySpinner();
                //popupDialog(countryArrayList);
    
    
            }
    
        }
    
        private void popupDialog(final ArrayList<SelectCountry> countryArrayList) {
            final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
    
            LayoutInflater inflater = this.getLayoutInflater();
            final View PopupLayout = inflater.inflate(R.layout.dialog_select_location_activity, null);
            helpBuilder.setView(PopupLayout);
    
             helpDialog = helpBuilder.create();
            helpDialog.setCancelable(false);
            helpDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            helpDialog.show();
            ImageView cancelImage=(ImageView)PopupLayout.findViewById(R.id.btnCancel);
            cancelImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    helpDialog.cancel();
                }
            });
            ListView listView=(ListView)PopupLayout.findViewById(R.id.listviewitems);
            listView.setAdapter(new CountryAdapter(countryArrayList));
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if(dialogID==0){
                        countryID=countryArrayList.get(position).getCountryCode();
                        countryTextView.setText(countryArrayList.get(position).getCountryName());
                        countryTextView.setTextColor(Color.WHITE);
                        MyUtility.showLog("Selected country id ",countryID);
                    }
                    else if(dialogID==1) {
                        provinceID = countryArrayList.get(position).getCountryCode();
                        provinceTextView.setText(countryArrayList.get(position).getCountryName());
                        provinceTextView.setTextColor(Color.WHITE);
                        MyUtility.showLog("Selected province id ",countryID);
                    }else if(dialogID==2){
                        cityID=countryArrayList.get(position).getCountryCode();
                        cityTextView.setText(countryArrayList.get(position).getCountryName());
                        cityTextView.setTextColor(Color.WHITE);
                        MyUtility.showLog("Selected city id ",countryID);
    
                    }else if(dialogID==3){
                        suberbID=countryArrayList.get(position).getCountryCode();
                        suberbTextView.setText(countryArrayList.get(position).getCountryName());
                        suberbTextView.setTextColor(Color.WHITE);
                        MyUtility.showLog("Selected suberb id ",countryID);
                    }
                    else if(dialogID==4){
                        categoryID=countryArrayList.get(position).getCountryCode();
                        categoryTextView.setText(countryArrayList.get(position).getCountryName());
                        suberbTextView.setTextColor(Color.WHITE);
                        MyUtility.showLog("Selected suberb id ",categoryID);
                    }
                    helpDialog.cancel();
    
                    }
    
            });
    
        }
    
    
        // this method fetch city category's items from server based on selected id
        private void signUpUser() {
    
            if (MyUtility.isConnected(SelectLocationActivity.this)) {
    
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(Constsants.SELECT_SIGNUP_SECONDPHASE, Constsants.SELECT_SIGNUP_SECONDPHASE));
                nameValuePairs.add(new BasicNameValuePair(Constsants.ID, sharedPreferenceManager.getUserDetails(this, Constsants.RESPONSE_USER_ID)));
                nameValuePairs.add(new BasicNameValuePair(Constsants.COUNTRY, countryID));
                nameValuePairs.add(new BasicNameValuePair(Constsants.PROVINCE, provinceID));
                nameValuePairs.add(new BasicNameValuePair(Constsants.CITY, cityID));
                nameValuePairs.add(new BasicNameValuePair(Constsants.SUBERB, suberbID));
                nameValuePairs.add(new BasicNameValuePair(Constsants.CATEGORY, categoryID));
                WebServiceTask lineDataServiceTask =
                        new WebServiceTask(SelectLocationActivity.this, ServerUrl.BASE_URL + ServerUrl.SECOND_SIGNUP_API, nameValuePairs, Constsants.SECOND_SIGNUP_API_CODE, this);
                lineDataServiceTask.execute();
                 }else{
                Toast.makeText(SelectLocationActivity.this, getResources().getString(R.string.internet_connectivity_msg), Toast.LENGTH_SHORT).show();
            }
    
        }
    
        /**
         * Adapter Class for Select country (Drop down)
         *
         * @author arpit
         */
        private class CountryAdapter extends BaseAdapter {
            private List<SelectCountry> selectCountries;
    
            public CountryAdapter(List<SelectCountry> countryArrayList) {
                // TODO Auto-generated constructor stub
                this.selectCountries = countryArrayList;
            }
    
            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return selectCountries.size();
            }
    
            @Override
            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return null;
            }
    
            @Override
            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return 0;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                if (convertView == null) {
                    convertView = getLayoutInflater().inflate(R.layout.spinner_custom_layout, null);
                }
                // selectedPosition=position;
    
    
                ((TextView) convertView.findViewById(R.id.countryNameTextView)).setText(selectCountries.get(position).getCountryName());
    
    
                return convertView;
            }
    
        }
    
        @Override
        public void onBackPressed() {
            super.onBackPressed();
            Intent intent=new Intent(SelectLocationActivity.this,ViewOffersActivity.class);
            intent.putExtra("callX", true);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
    
    
        }
    }
    

 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: