Как добавить флажок Dynami c в диалог android? - PullRequest
0 голосов
/ 10 января 2020

она - мой код, и я также добавляю ответ от 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);
}

вот мой ответ от API. Я хочу показать это время динамически c в диалоговом окне после для l oop, пожалуйста, помогите me Заранее спасибо

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

Мне нужно показать время в диалоге с флажком Dynami c Вот мой макет диалога

   <?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>

...