我有作业,我被告知要显示从数据库到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,我使用的是singleton
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);
输出只是一个按钮,数组没有出来,我修改了它,但仍然不起作用,我的代码有什么问题吗?
请帮忙
暂无答案!
目前还没有任何答案,快来回答吧!