2016-03-31 9 views
0

Ich habe ListView in meiner App, es zeigt sich im Emulator, aber wenn ich es in realen Gerät versuchte es nicht ... es post auf Server und erhalten JSON-Format im Gegenzug und zeigen sie in Listenansicht ...Im Emulator meine App läuft gut, aber nicht in Echtgerät

ich habe zwei Layouts, erste 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> 

Sekunde 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> 

und dies ist mein Code-Parameter-Server zu schreiben:

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; 
      } 
     }; 
+0

Haben Sie versucht, Dummy-Listen nur zu Testzwecken hinzuzufügen? –

+0

ja, ich habe ... und es ist in Ordnung – meeftah

+0

Dann sagen Sie, Dummy-Liste wird in beiden angezeigt. Aber die Liste, die Sie vom Server holen mussten, wird nicht in einem echten Gerät angezeigt, oder? –

Antwort

Verwandte Themen