This is my actual JSON response from server. Here 3rd object contains url. In android alert dialog single choice when get 3rd object, I need those radio options in images.
{
"quiz":[
{
"time":10,
"q_id":"1",
"label":"1.First Question",
"option":[
"a",
"b",
"c",
"d"
]
},
{
"time":20,
"q_id":"2",
"label":"2.Second Question",
"option":[
"e",
"f",
"g",
"h"
]
},
{
"time":50,
"q_id":"3",
"label":"3.Third Question",
"option":[
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcShqRPmJQo0Jw20ryifdlUUm4iFuEGktmEfCZaEM8lJITVxNnK4rw",
"https://drop.ndtv.com/albums/SPORTS/ct2017_ind_pak/thumb_640x480.jpg",
"https://drop.ndtv.com/albums/SPORTS/ct2017_ind_pak/thumb_640x480.jpg",
"https://drop.ndtv.com/albums/SPORTS/ct2017_ind_pak/thumb_640x480.jpg"
]
}
]
}
This is my android code. Here I need to change the radio button text into image. In case json object get as URL. How can get those?
for (int i = 0; i < jsonArray.length(); i++) {
try {
jsonObject = jsonArray.getJSONObject(i);
JSONArray array = new JSONArray(jsonObject.getString("option"));
if (time == Integer.parseInt(jsonObject.getString("time"))) {
running = false;
mp.pause();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Page03.this);
alertDialogBuilder.setCancelable(false);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new ActionBar.
LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT));
params.setMargins(5, 5, 5, 5);
params.gravity = Gravity.CENTER;
final TextView alertdiaglogtitle = new TextView(Page03.this);//title
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/sffb.ttf");//custom font
alertdiaglogtitle.setTypeface(face);
alertdiaglogtitle.setTextSize(20);
alertdiaglogtitle.setPadding(10, 5, 5, 5);
alertdiaglogtitle.setLayoutParams(params);
alertDialogBuilder.setCustomTitle(alertdiaglogtitle);
alertdiaglogtitle.setText(jsonObject.getString("label"));
final String quetionid = jsonObject.getString("q_id");
for (int j = 0; j < array.length(); j++) {
timing.add(array.get(j).toString());
if (Patterns.WEB_URL.matcher(array.get(j).toString()).matches()) {
Toast.makeText(Page03.this, "valid", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Page03.this, "Not valid", Toast.LENGTH_SHORT).show();
}
}
CharSequence[] cs = timing.toArray(new CharSequence[timing.size()]);
timing.clear();
alertDialogBuilder.setSingleChoiceItems(cs, -1, new DialogInterface
.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
}
});
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
ListView lw = ((AlertDialog) arg0).getListView();
checkedItem = (String) lw.getAdapter().getItem(lw.getCheckedItemPosition());
Toast.makeText(Page03.this, quetionid.toString() + "------" + checkedItem.toString(), Toast.LENGTH_SHORT).show();
arg0.dismiss();
mp.start();
running = true;
}
});
alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}