vendredi 10 janvier 2020

How to add Dynamic Checkbox in Dialog android?

her is my code and I also add response from API

   private void callDoctorTiming() {
    String request_url = GlobeStrings.BaseUrl + "/doctor-admin/apis/app.php?api=doctorTiming";
    pd = new ProgressDialog(getActivity());
    pd.setMessage(getResources().getString(R.string.Loading));
    pd.show();
    RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
    final String response = null;
    final String finalResponse = response;
    StringRequest postRequest = new StringRequest(com.android.volley.Request.Method.POST,
            request_url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            pd.dismiss();
            Log.e("@@TimeApi", response);
            try {
                JSONObject obj = new JSONObject(response);
                JSONObject objData = obj.getJSONObject("data");
                JSONArray jsonArray = objData.getJSONArray("time");



                if (!obj.getBoolean("error")) {

                    for (int i=0; i<jsonArray.length(); i++){


                    }

                } else {
                    Toast.makeText(getActivity(), obj.getString("message"), Toast.LENGTH_SHORT).show();
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    pd.dismiss();
                    Log.e(TAG, "error in api " + error.getMessage());
                }
            }
    ) {
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("doctor_id", "" + doctorID);
            params.put("available_date", date);
           // params.put("available_date", "" + date);
            return params;
        }
    };
    postRequest.setRetryPolicy(new DefaultRetryPolicy(0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    requestQueue.add(postRequest);
}

here is my response from API I want to show this time dynamic in dialog after for loop, please help me Thank you in advance

{
"error": false,
"data": {
    "time": [
        "02:00 PM-08:00 PM",
        "09:00 PM-11:30 PM"
    ]
},
"message": "success"
 }

I need to show time in dialog with checkbox dynamic here is my dialog layout

   <?xml version="1.0" encoding="utf-8"?>
   <androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:elevation="@dimen/margin5"
app:cardCornerRadius="@dimen/margin5"
android:orientation="vertical">

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

 <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

  <TextView
    android:id="@+id/message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/Are_you_sure_to_logout"
    android:gravity="center"
    android:textColor="#000000"
    android:textSize="15dp"
     android:layout_marginTop="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginLeft="15dp"
    android:layout_gravity="center_vertical"
    />
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="15dp">

     <TextView
    android:layout_width="0dp"
    android:layout_weight="0.50"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:text="@string/Confirm"
    android:gravity="center"
    android:background="#2196F3"
    android:textColor="#fff"
    android:padding="5dp"
    android:layout_marginRight="1dp"
    android:id="@+id/d_confirm"/>

       <TextView
           android:layout_width="0dp"
           android:layout_weight="0.50"
           android:layout_height="wrap_content"
           android:textSize="15dp"
           android:text="@string/Cancel"
           android:gravity="center"
           android:background="#2196F3"
           android:textColor="#fff"
           android:padding="5dp"
           android:layout_marginLeft="1dp"
           android:id="@+id/d_cancel"/>
   </LinearLayout>



Aucun commentaire:

Enregistrer un commentaire