Forum für diejenigen, die für Android programmieren
Guest
Wie zeige ich jedes Abfrageergebnis in einer einzelnen Zeile mit JSON an?
Post
by Guest » 05 Feb 2025, 00:37
Ich entwickle eine Anwendung, um Client -Bestellungen zu empfangen. Informationen werden angezeigt als: < /p>
Code: Select all
Tomato quantity 4,Strawberry quantity 6
**How to display them like :**
*Tomato quantity 4
Strawberry quantity 6*
I mean each order name with the quantity on a single line
< /code>
So erhalte ich die Informationen: < /p>
[b] Dies ist mein JSON -Code: [/b]
public class BackgroundTask extends AsyncTask {
Context ctx;
Activity activity;
RecyclerView recyclerView;
RecyclerView.Adapter adapter;
RecyclerView.LayoutManager layoutManager;
ProgressDialog progressDialog;
ArrayListarrayList= new ArrayList();
public BackgroundTask(Context ctx)
{
this.ctx=ctx;
activity=(Activity)ctx;
}
String json_string = "\\";
@Override
protected void onPreExecute() {
recyclerView=(RecyclerView)activity.findViewById(R.id.recyclerView);
layoutManager=new LinearLayoutManager(ctx);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
adapter=new RecyclerAdapter(arrayList);
recyclerView.setAdapter(adapter);
progressDialog = new ProgressDialog(ctx);
progressDialog.setTitle("Please Wait..");
progressDialog.setMessage("List is loading..");
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.show();
}
@Override
protected void onProgressUpdate(Order... values) {
arrayList.add(values[0]);
adapter.notifyDataSetChanged();
}
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
}
@Override
protected Void doInBackground(Void... params) {
try
{
URL url = new URL(json_string);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n\t");
}
httpURLConnection.disconnect();
String json_string = stringBuilder.toString().trim();
JSONObject jsonObject = new JSONObject(json_string);
JSONArray jsonArray = jsonObject.getJSONArray("server_response");
int count=0;
while(count
Mein PHP -Code < /strong>: < /p>
1738712252
Guest
Ich entwickle eine Anwendung, um Client -Bestellungen zu empfangen. Informationen werden angezeigt als: < /p> [code]Tomato quantity 4,Strawberry quantity 6 **How to display them like :** *Tomato quantity 4 Strawberry quantity 6* I mean each order name with the quantity on a single line < /code> So erhalte ich die Informationen: < /p> [b] Dies ist mein JSON -Code: [/b] public class BackgroundTask extends AsyncTask { Context ctx; Activity activity; RecyclerView recyclerView; RecyclerView.Adapter adapter; RecyclerView.LayoutManager layoutManager; ProgressDialog progressDialog; ArrayListarrayList= new ArrayList(); public BackgroundTask(Context ctx) { this.ctx=ctx; activity=(Activity)ctx; } String json_string = "\\"; @Override protected void onPreExecute() { recyclerView=(RecyclerView)activity.findViewById(R.id.recyclerView); layoutManager=new LinearLayoutManager(ctx); recyclerView.setLayoutManager(layoutManager); recyclerView.setHasFixedSize(true); adapter=new RecyclerAdapter(arrayList); recyclerView.setAdapter(adapter); progressDialog = new ProgressDialog(ctx); progressDialog.setTitle("Please Wait.."); progressDialog.setMessage("List is loading.."); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); progressDialog.show(); } @Override protected void onProgressUpdate(Order... values) { arrayList.add(values[0]); adapter.notifyDataSetChanged(); } @Override protected void onPostExecute(Void result) { progressDialog.dismiss(); } @Override protected Void doInBackground(Void... params) { try { URL url = new URL(json_string); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); InputStream inputStream = httpURLConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line + "\n\t"); } httpURLConnection.disconnect(); String json_string = stringBuilder.toString().trim(); JSONObject jsonObject = new JSONObject(json_string); JSONArray jsonArray = jsonObject.getJSONArray("server_response"); int count=0; while(count Mein PHP -Code < /strong>: < /p> [/code]
0 Replies
9 Views
Last post by Anonymous
05 Feb 2025, 00:37
0 Replies
0 Views
Last post by Anonymous
03 Jun 2025, 07:37
0 Replies
9 Views
Last post by Anonymous
13 Apr 2025, 10:41
0 Replies
33 Views
Last post by Guest
13 Feb 2025, 12:09
0 Replies
18 Views
Last post by Guest
08 Feb 2025, 17:53