I have ListView in my app, it shows up in emulator but when I tried in real device it did not...it post to server and get json format in return and show it in listview...
I have two layouts, first hasilpencarian_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/colorGray">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/header1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimary"
android:padding="5dp"
android:orientation="vertical">
<ImageButton
android:id="@+id/btn_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_circled_back"
android:tint="@color/colorPrimaryDark"
android:background="@null"
android:padding="10dp"
android:layout_marginTop="5dp" />
<Button
android:id="@+id/waktu"
android:text="waktu"
android:textSize="15sp"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/header2"
android:layout_below="@+id/header1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimary"
android:padding="5dp"
android:orientation="vertical">
<com.rey.material.widget.EditText
android:id="@+id/kotaasalLengkap"
android:text="Dari"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/carmoving"
android:layout_centerVertical="true"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:editable="false"
app:et_dividerColor="@color/colorPrimary"
app:et_dividerHeight="2dp" />
<ImageView
android:id="@+id/carmoving"
android:src="@drawable/ic_taxi"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<com.rey.material.widget.EditText
android:id="@+id/kotatujuanLengkap"
android:text="Ke"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/carmoving"
android:layout_centerVertical="true"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:editable="false"
app:et_dividerColor="@color/colorPrimary"
app:et_dividerHeight="2dp" />
</RelativeLayout>
<ImageView
android:id="@+id/strip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/strip_repeat"
android:layout_marginTop="75dp"/>
<solar.blaz.date.week.WeekDatePicker
android:id="@+id/date_picker"
android:layout_below="@+id/strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="@color/date_picker_day_textcolor"
android:textSize="18sp"
app:wdp_labelTextSize="12sp"
app:wdp_labelPadding="5dp"
app:wdp_dayBackground="@drawable/date_picker_day_bg"
app:wdp_firstDayOfWeek="monday"
app:wdp_labelTextColor="@color/colorWhite"/>
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:textSize="15sp"
android:gravity="center"
android:text=""/>
<ListView
android:id="@+id/listtaxi"
android:layout_below="@+id/date_picker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_row_selector" />
</RelativeLayout>
second, list_row_taxi.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_row_selector"
android:padding="8dp" >
<!-- Thumbnail Image -->
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/thumbnail"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp" />
<!-- Nama Taxi / mitra -->
<TextView
android:id="@+id/namataxi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:textSize="@dimen/namataxi"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
<!-- icon jam -->
<ImageView
android:id="@+id/ic_waktu"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_action_action_query_builder"
android:layout_toRightOf="@+id/thumbnail"
android:layout_below="@+id/namataxi"/>
<!-- waktu -->
<TextView
android:id="@+id/waktu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/namataxi"
android:layout_marginTop="3dip"
android:layout_toRightOf="@+id/ic_waktu"
android:textSize="@dimen/waktu"
android:textColor="@color/colorWhiteFade" />
<!-- Jumlah kursi yang teredia -->
<TextView
android:id="@+id/kursi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/waktu"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/thumbnail"
android:textColor="@color/kursi"
android:textSize="@dimen/kursi" />
<!-- Tarif -->
<TextView
android:id="@+id/tarif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textColor="@color/colorYellowDark"
android:textSize="@dimen/tarif" />
</RelativeLayout>
and this is my code to post parameters to server:
StringRequest strReq = new StringRequest(Request.Method.POST,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
dialog.dismiss();
try{
JSONObject obj = new JSONObject(response);
JSONArray arr = obj.getJSONArray("daftar_taxi");
for (int i = 0; i < arr.length(); i++) {
JSONObject c = arr.getJSONObject(i);
Taxi taxi = new Taxi();
taxi.setNamataxi(c.getString("mitra_nama"));
taxi.setThumbnailUrl(c.getString("image"));
taxi.setWaktu(c.getString("wkt_berangkat") + " - " + c.getString("wkt_sampai"));
taxi.setKursi("Kursi yang tersedia: " + c.getInt("jml_kursi"));
taxi.setTarif(c.getInt("tarif"));
taxiList.add(taxi);
Log.d(TAG, taxiList.toString());
}
}catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
dialog.dismiss();
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("dari", textkodeasal_btn);
params.put("ke", textkodetujuan_btn);
params.put("jml_penumpang", jml_penumpang);
Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
Possible duplicate: Android ListView not showing on real device but on emulator does
You can Check if the problem is same with your code. Otherwise you can check for this solution too. Android app working on emulator but not on real device
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.