0

I have to display the java script object notation parse data into the alert dialog box of an android. Is it possible? If we see the play store app and if we want to buy or subscribe some movie, then it shows the alert dialog, along with the movie banner thumbnail, movie name, its price and the continue button. Further if you click on continue button another dialog box is open. So anyone can help me, how to create it? This is the sample image of play store. I want to create this type of dialog in my application. Kindly suggest me weather it is possible or not. enter image description here

Here is the Code

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.cartBookDescription);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          inputDialog()
        }
    });

 void inputDialog() {


    try {


       textView.setText("my order");
       dbhelper.openDataBase();
    } catch (SQLException sqle) {
        throw sqle;
    }

    LayoutInflater layoutInflater = LayoutInflater.from(this);
    View alertDialog = layoutInflater.inflate(R.layout.alert_dialog, null);

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setView(alertDialog);



    alert.setTitle("Order Now");

    alert.setCancelable(false);
  alert.setView(edtQuantity);

    alert.setPositiveButton("Subscribe Now", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            int quantity = 0;


         } else {
                dialog.cancel();
          }
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {


            dialog.cancel();
        }
    });

    alert.show();
}
public void parseJSONData() {

    try {
        // request data from menu detail API
        HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout((HttpParams) client.getParams(), 15000);
        HttpConnectionParams.setSoTimeout((HttpParams) client.getParams(), 15000);
        HttpUriRequest request = new HttpGet(MenuDetailAPI);
        HttpResponse response = client.execute(request);
        InputStream atomInputStream = response.getEntity().getContent();


        BufferedReader in = new BufferedReader(new InputStreamReader(atomInputStream));

        String line;
        String str = "";
        while ((line = in.readLine()) != null) {
            str += line;
        }


        JSONObject json = new JSONObject(str);
        JSONArray data = json.getJSONArray("Book"); // this is the "items: [ ] part

        for (int i = 0; i < data.length(); i++) {
            JSONObject object = data.getJSONObject(i);


            Detail_id = object.getString("id");
            Detail_audio = object.getString("audiofile");
            Detail_bookauthor = object.getString("bookauthor");
            Detail_image = object.getString("photo");
            Detail_name = object.getString("bookname");
            Detail_category = object.getString("bookcategory");
            Detail_premium = object.getString("premiumtype");
            Detail_price = Double.valueOf(formatData.format(object.getDouble("price")));
            Detail_validity = Integer.valueOf((object.getInt("validity")));             
            Detail_description = object.getString("description");

        }


    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (JSONException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

parseJson method is written under asyncTask. Json data is parsing properly but when I am trying to show that data in the alert dialog, the alert dialog gets crashed.

Fazeel Qureshi
  • 727
  • 8
  • 16

2 Answers2

0

Yes, you can. You just need to parse the data and create a custom dialog by creating an activity and a layout class. Example can be seen here

Kharda
  • 1,070
  • 11
  • 18
  • it is only showing custom dialog. Kindly suggest me to show json data in it. – Fazeel Qureshi Aug 02 '17 at 08:09
  • Have you succeeded to parse the data? If yes, then you can pass it via bundle. Here is the example http://android-coding.blogspot.co.id/2012/05/custom-dialog-with-data-passed-in.html. – Kharda Aug 02 '17 at 08:15
0

you have to create xml file for custom view and the add what you want to show in alert dialog as per your requirment refer this link How to create a Custom Dialog box in android? or https://bhavyanshu.me/tutorials/create-custom-alert-dialog-in-android/08/20/2015

Mahesh Gawhane
  • 345
  • 3
  • 18