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