Singleton JSON получить данные из базы данных в мое приложение - PullRequest
0 голосов
/ 02 декабря 2018

Я получил домашнее задание, мне сказали отображать данные из базы данных в приложение Android, но мой код не отображает ничего, только пустую страницу

это мой xml

<LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true">

        <Button
            android:id="@+id/btn_activity_main_pindah"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/texttotal"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:background="#7ec6ef"
            android:text="Pindah"
            android:onClick="Pindah"
            />

    </LinearLayout>

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout"
        android:layout_centerHorizontal="true">

        <TextView
            android:id="@+id/txtDisplay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp" />
    </ScrollView>

это мой java, я использую синглтон

String url= "http://testtest/bulanan.php?";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    JSONArray jsonarray = new JSONArray(response);
                    StringBuilder textViewData = new StringBuilder();
                    //Parse the JSON response array by iterating over it
                    for (int i = 0; i < jsonarray.length(); i++) {
                        JSONObject jsonobject = jsonarray.getJSONObject(i);
                        String id = jsonobject.getString(KEY_ID);
                        String tipe = jsonobject.getString(KEY_TIPE);
                        String waktu = jsonobject.getString(KEY_WAKTU);
                        String totalltr = jsonobject.getString(KEY_TOTALLTR);
                        String total = jsonobject.getString(KEY_TOTAL);
                        //Create String out of the Parsed JSON
                        textViewData.append("id: ").append(id).append(NEW_LINE);
                        textViewData.append("tipe: ").append(tipe).append(NEW_LINE);
                        textViewData.append("waktu: ").append(waktu).append(NEW_LINE);
                        textViewData.append("totalltr: ").append(totalltr).append(NEW_LINE);
                        textViewData.append("total: ").append(total).append(NEW_LINE);
                        textViewData.append(NEW_LINE);
                    }
                    //Populate textView with the response
                    mTxtDisplay.setText(textViewData.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if(error != null){
                    Toast.makeText(getApplicationContext(), "Something went wrong.", Toast.LENGTH_LONG).show();
                }
            }
        }
);

MySingleton.getInstance(getApplicationContext()).addToRequestQueue(stringRequest);

вывод - просто кнопка, массив не выходит, я изменил его, но он все еще не работает, есть что-то не такс моим кодом?

помогите пожалуйста

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...