2017-01-05 2 views
0

Hallo Ich erstelle ein Layout und ein ListView darin, kleines Symbol in 5 Spalten anzuzeigen. Ich verwende AysncTask, um JSON zu analysieren, um die Bilddetails zu erhalten, die ich in der Listenansicht anzeigen muss. Jetzt bekomme ich Fehler. Ich weiß nicht, wie ich es lösen soll. Bitte hilf mir zu lösen.Wie zum Aufblasen Fehler in Android?

Mein Layout ist:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_seatvisible" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.notebook.runtowin.Activity.Seatvisible"> 


     <TextView 
      android:id="@+id/from_to" 
      android:layout_width="match_parent" 
      android:layout_height="35sp" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentTop="true" 
      android:background="@color/colorPrimaryDark" 
      android:text="Select your seat" 
      android:padding="5sp" 
      android:gravity="center_vertical" 
      android:textStyle="bold" 
      android:textColor="@color/colorwhite" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_below="@+id/from_to"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:background="#FFEB3B" 
      android:id="@+id/headinglayout"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/busname" 
        android:padding="5sp" 
        android:text="RUN TO WIN" 
        android:textStyle="bold"/> 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_below="@+id/busname" 
       > 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/seatnumber" 
        android:padding="5sp" 
        android:text="Seats :"/> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="@+id/seatnumber" 
        android:text="25,24" 
        android:id="@+id/seatsnumber"/> 

      </LinearLayout> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/ticketprice" 
       android:layout_alignParentRight="true" 
       android:text="hsdshd" 
       android:textStyle="bold" 
       android:padding="5sp" 
       android:textSize="30sp" 
       android:layout_marginRight="10sp"/> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_below="@+id/headinglayout" 
      android:layout_marginTop="3sp" 
      android:paddingTop="10sp" 
      android:paddingRight="25sp" 
      android:paddingLeft="25dp"> 

      <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/iconsteer" 
       android:id="@+id/imageView2" 
       android:layout_marginEnd="50sp" 
       android:layout_alignParentEnd="true"/> 

      <ListView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/imageView2" 
       android:layout_marginTop="20sp" 
       android:id="@+id/listviewseat"> 

      </ListView> 


     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="25sp" 
      android:layout_alignParentEnd="true" 
      android:gravity="center_horizontal" 
      android:background="@color/colorPrimaryDark" 
      > 
      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="BOOK TICKETS" 
       android:padding="10sp" 
       android:id="@+id/bt_book" 
       android:textSize="20sp"/> 
     </RelativeLayout> 
    </LinearLayout> 

</RelativeLayout> 

Mein Listview-Layout ist:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="8sp" 
    android:gravity="top"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageViewseat"/> 

</LinearLayout> 

Mein Code ist:

public class Seatvisible extends AppCompatActivity { 

ArrayList<HashMap<String, String>> busdetails1; 

private String BusID, servicedate; 
private static String url="http://appsilonz.com/demo/v2/bus_seat_abhi.php?journey_date=2017-01-05&bus_id=20"; 
private ListView lv; 
private TextView busname, from_to, seatsnumber, ticketprice; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_seatvisible); 

    lv = (ListView) findViewById(R.id.listviewbusdetails); 
    inilize(); 

    new Seatparsing().execute(); 

} 

private void inilize() { 

    Intent intent = getIntent(); 
    BusID = intent.getStringExtra("BusID"); 
    servicedate = intent.getStringExtra("servicedate"); 
    busname = (TextView) findViewById(R.id.busname); 
    from_to = (TextView) findViewById(R.id.from_to); 
    seatsnumber = (TextView) findViewById(R.id.seatsnumber); 
    ticketprice = (TextView) findViewById(R.id.ticketprice); 


} 

public class Seatparsing extends AsyncTask<String, String, ArrayList<HashMap<String, String>>> { 

    String response; 
    String jsonstr, seat_name, ticket_status, seatladies; 
    ProgressDialog dialog = new ProgressDialog(Seatvisible.this); 
    AndroidHttpClient maclient = AndroidHttpClient.newInstance(""); 

    @Override 
    protected void onPreExecute() { 
     dialog.setCancelable(false); 
     dialog.setMessage("Please wait.."); 
     dialog.setIndeterminate(false); 
     dialog.show(); 

    } 

    @Override 
    protected ArrayList<HashMap<String, String>> doInBackground(String... params) { 


     HttpGet request = new HttpGet(url); 
     ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
     try { 
      response = maclient.execute(request, responseHandler); 
     } catch (ClientProtocolException exception) { 
      exception.printStackTrace(); 
      return null; 
     } catch (IOException exception) { 
      exception.printStackTrace(); 
      return null; 
     } 
     Log.i("Seats", "" + response); 
     Log.i("seaturl", "" + url); 

     jsonstr = response; 
     busdetails1 = new ArrayList<>(); 

     if (jsonstr != null) { 

      HashMap<String, String> map2 = new HashMap<>(); 
      try { 
       JSONArray array1 = new JSONArray(jsonstr); 
       for (int i = 0; i < array1.length(); i++) { 
        JSONObject objct1 = array1.getJSONObject(i); 
        JSONArray array2 = objct1.getJSONArray("row1"); 
        for (int j = 0; j < array2.length(); j++) { 
         JSONObject objct2 = array2.getJSONObject(j); 

         seat_name = objct2.getString("seat_name ").toString(); 
         ticket_status = objct2.getString("ticket_status"); 
         seatladies = objct2.getString("seatIsLadies"); 

         map2.put("seat_name", seat_name); 
         map2.put("ticket_status", ticket_status); 
         map2.put("seatIsLadies", seatladies); 

        } 
        busdetails1.add(map2); 
       } 
      } catch (Exception e) { 
      e.printStackTrace(); 
      } 
     } 

     return busdetails1; 

    } 

    protected void onPostExecute(ArrayList<HashMap<String, String>> busdetails1) { 


     dialog.dismiss(); 

     customadapter adapter = new customadapter(getApplicationContext(), R.layout.seatlistview, busdetails1); 
     lv.setAdapter(adapter); 
    } 
} 

public class customadapter extends ArrayAdapter { 

    private ArrayList<HashMap<String, String>> list; 
    private int resource; 
    private LayoutInflater inflater; 

    public customadapter(Context context, int resource, ArrayList<HashMap<String, String>> busdetails1) { 
     super(context, resource, busdetails1); 

     list = busdetails1; 
     this.resource = resource; 
     inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 


    } 

    @NonNull 
    @Override 
    public View getView(int i, View convertView, ViewGroup parent) { 

     convertView = inflater.inflate(resource, null); 

     ImageView imageView = (ImageView) convertView.findViewById(R.id.imageViewseat); 

     String seat_name = list.get(i).get("seat_name"); 
     String ticket_status = list.get(i).get("ticket_status"); 
     String seatIsLadies = list.get(i).get("seatIsLadies"); 

     if (!seat_name.equals(null)) { 

      if (ticket_status.equals("booked")) { 
       if (seatIsLadies.equals("true")) { 
        imageView.setImageResource(R.drawable.reservedladies); 
        imageView.setClickable(false); 
       } else { 
        imageView.setImageResource(R.drawable.bookedseat); 
        imageView.setClickable(false); 
       } 

      } else { 
       imageView.setImageResource(R.drawable.available_seat_img); 


      } 

     } else { 

      imageView.setImageDrawable(null); 
      imageView.setClickable(false); 


     } 


     return convertView; 
    } 
} 

}

+0

Verwendung einstellen dp anstelle von sp für alle Dimensionen außer Textgröße –

Antwort

1

Sie sollten dp für Dimensionen verwenden und sp für textSize. Zur Zeit verwenden Sie sp für Dimensionen.

Siehe bearbeitet unter Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_seatvisible" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.notebook.runtowin.Activity.Seatvisible"> 


    <TextView 
     android:id="@+id/from_to" 
     android:layout_width="match_parent" 
     android:layout_height="35dp" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:background="@color/colorPrimaryDark" 
     android:text="Select your seat" 
     android:padding="5dp" 
     android:gravity="center_vertical" 
     android:textStyle="bold" 
     android:textColor="@color/colorwhite" /> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_below="@+id/from_to"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:background="#FFEB3B" 
     android:id="@+id/headinglayout"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/busname" 
       android:padding="5dp" 
       android:text="RUN TO WIN" 
       android:textStyle="bold"/> 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_below="@+id/busname" 
      > 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/seatnumber" 
       android:padding="5dp" 
       android:text="Seats :"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="5dp" 
       android:text="25,24" 
       android:id="@+id/seatsnumber"/> 

     </LinearLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/ticketprice" 
      android:layout_alignParentRight="true" 
      android:text="hsdshd" 
      android:textStyle="bold" 
      android:padding="5dp" 
      android:textSize="30sp" 
      android:layout_marginRight="10dp"/> 

    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_below="@+id/headinglayout" 
     android:layout_marginTop="3dp" 
     android:paddingTop="10dp" 
     android:paddingRight="25dp" 
     android:paddingLeft="25dp"> 

     <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/iconsteer" 
      android:id="@+id/imageView2" 
      android:layout_marginEnd="50dp" 
      android:layout_alignParentEnd="true"/> 

     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/imageView2" 
      android:layout_marginTop="20dp" 
      android:id="@+id/listviewseat"> 

     </ListView> 


    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="25dp" 
     android:layout_alignParentEnd="true" 
     android:gravity="center_horizontal" 
     android:background="@color/colorPrimaryDark" 
     > 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="BOOK TICKETS" 
      android:padding="10dp" 
      android:id="@+id/bt_book" 
      android:textSize="20sp"/> 
    </RelativeLayout> 
</LinearLayout> 

Für Listview-Layout,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="8dp" 
    android:gravity="top"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageViewseat"/> 

</LinearLayout> 

Auch Sie können nicht layout_marginRight zu einem id an dieser Linie,

android:layout_marginRight="@+id/seatnumber" 

Sie wahrscheinlich gemeint,

Siehe @Baseem Samys Antwort auch.

+0

das stimmt, aber der Fehler war nicht wegen sp es ist, weil er eine Marge direkt auf eine ID gesetzt –

+0

@BassemSamy Oh ich verpasste das! –

+0

@Bassem, Neeraj, uguboz..thankyou ... es funktioniert ... BT jetzt ist die Aktivität sichtbar und nach ein paar Sekunden ging es zur vorherigen Seite.Ich debugge und finde, dass ich einen Fehler in Ayanctask Parsing auf "Return BusDetails "im Hintergrund..i aktualisiert meinen Code .. – kavin

0

Ich sehe SP-Einheiten in Ihren Layout-Dateien für die Padding-Größe. sp steht für die Schriftgröße nur, wenn dp oder dip für alle Dimensionen gilt.

0

im Textview mit id android: id = "@ + id/seatsnumber" Sie layout_marginRight zu einem id gesetzt, das ist in Android nicht verfügbar Sie keine Polsterung mit Blick

<TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="@+id/seatnumber" 
        android:text="25,24" 
        android:id="@+id/seatsnumber"/> 
Verwandte Themen