我必須將java腳本對象表示法解析數據顯示到android的alert對話框中。可能嗎?如果我們看到Play商店應用,並且想要購買或訂閱某部電影,則會顯示提醒對話框以及電影橫幅縮略圖,電影名稱,價格和繼續按鈕。此外,如果你點擊繼續按鈕,另一個對話框打開。所以任何人都可以幫助我,如何創建它?這是Play商店的示例圖片。我想在我的應用程序中創建這種類型的對話框。請建議我天氣有可能與否。 如何在android alert對話框中顯示json解析數據?
這裏是
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方法的AsyncTask下編寫的代碼。 Json數據解析正常,但當我試圖在警報對話框中顯示數據時,警報對話框會崩潰。
您是否嘗試過的東西?任何想法? – xAqweRx
是的,我已經創建了一個XML佈局文件,並在警報對話框中充氣。但是我想在其中顯示json數據。該佈局包含一個imageview和兩個textview –
@xAqweRx任何幫助? –