2017-06-24 3 views
1

Wie wird diese einzelne Zeile in jeder erweiterbaren Listenansicht als statisch hinzugefügt?So fügen Sie eine statische Zeile in der erweiterbaren Listenansicht hinzu

enter image description here

das ist mein Layout inflater:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <RelativeLayout 
    android:padding="5dp" 
     android:layout_marginTop="20dp" 
    android:layoutDirection="ltr" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 



     <TextView 
      android:text="#" 
      android:id="@+id/txt_rank_standings" 
      android:textSize="16sp" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentLeft="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:text="TEAM" 
      android:id="@+id/txtteam" 
      android:textSize="16sp" 
      android:layout_marginLeft="15dp" 
      android:layout_marginStart="15dp" 
      android:layout_toRightOf="@+id/txt_rank_standings" 
      android:layout_toEndOf="@+id/txt_rank_standings" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:id="@+id/textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="15dp" 
      android:textSize="16sp" 
      android:layout_marginEnd="15dp" 
      android:layout_toLeftOf="@+id/txt_points_standings" 
      android:layout_toStartOf="@+id/txt_points_standings" 
      android:text="P" /> 

     <TextView 
      android:id="@+id/txt_points_standings" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="15dp" 
      android:textSize="16sp" 
      android:layout_marginEnd="15dp" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:text="PTS" /> 
     <TextView 
      android:id="@+id/txt_rank_standings_final" 
      android:textSize="16sp" 
      android:textColor="#FFFFFF" 
      android:text="10" 
      android:layout_marginTop="15dp" 
      android:layout_below="@+id/txt_rank_standings" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentLeft="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:id="@+id/txt_name_standings_final" 
      android:textSize="16sp" 
      android:text="العهد" 
      android:layout_below="@+id/txtteam" 
      android:layout_marginTop="15dp" 
      android:layout_toEndOf="@+id/txt_rank_standings_final" 
      android:layout_toRightOf="@+id/txt_rank_standings_final" 
      android:layout_marginLeft="15dp" 
      android:layout_marginStart="15dp" 
      android:textColor="#FFFFFF" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    <TextView 
     android:id="@+id/txt_played_standings_final" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="20dp" 
     android:layout_marginEnd="20dp" 
     android:layout_marginTop="15dp" 
     android:textColor="@color/yellow" 
     android:layout_below="@+id/textView" 
     android:text="6" 
     android:layout_toLeftOf="@+id/txt_points_standings_final" 
     android:layout_toStartOf="@+id/txt_points_standings_final" 
     /> 

     <TextView 
      android:id="@+id/txt_points_standings_final" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:layout_marginEnd="20dp" 
      android:textColor="@color/yellow" 
      android:text="12" 
      android:layout_marginTop="15dp" 
      android:layout_below="@+id/txt_points_standings" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      /> 
</RelativeLayout> 
</android.support.design.widget.CoordinatorLayout> 

ich diese einzelne Zeile, um das Layout inflater hinzugefügt, aber das Problem, das ich so etwas wie dieses bin immer ist:

enter image description here

Die einzelne Zeile wird in der erweiterbaren Listenansicht dreimal wiederholt.

Also, wie mache ich diese Zeile statisch in der erweiterbaren Listview?

AKTUALISIERT:

Dies ist Aktivität mein Fragment, das das expandablelistview enthält:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/coordinatorLayout" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 


      <android.support.v4.widget.SwipeRefreshLayout 
       android:id="@+id/swipe_refresh" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
       <ExpandableListView 
        android:id="@+id/elv" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
       </ExpandableListView> 
      </android.support.v4.widget.SwipeRefreshLayout> 


</android.support.design.widget.CoordinatorLayout> 

Dies ist die benutzerdefinierte Zeile Layout:

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    android:padding="10dp" 
    android:id="@+id/relative_standings" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <TextView 
     android:text="#" 
     android:id="@+id/txt_rank_standings" 
     android:textSize="16sp" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:text="TEAM" 
     android:textSize="16sp" 
     android:layout_marginLeft="15dp" 
     android:layout_marginStart="15dp" 
     android:layout_toRightOf="@+id/txt_rank_standings" 
     android:layout_toEndOf="@+id/txt_rank_standings" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="15dp" 
     android:textSize="16sp" 
     android:layout_marginEnd="15dp" 
     android:layout_toLeftOf="@+id/txt_points_standings" 
     android:layout_toStartOf="@+id/txt_points_standings" 
     android:text="P" /> 

    <TextView 
     android:id="@+id/txt_points_standings" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="15dp" 
     android:textSize="16sp" 
     android:layout_marginEnd="15dp" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:text="PTS" /> 
</RelativeLayout> 

AKTUALISIERT:

Wenn ich hinzugefügt Das Header-Layout funktioniert, aber die erste untergeordnete Zeile wird entfernt Bild zeigt:

enter image description here

Antwort

1

Werfen Sie einen Blick auf diese Artikel, die Schritt für Schritt Anleitung, wie zu erreichen ist nur, dass - https://robusttechhouse.com/how-to-add-header-footer-to-expandablelistview-childview/

Um eine erweiterbare Listenansicht mit einem Header in dem Kind zu schaffen Ansicht benötigen Sie vier XML-Layoutdateien.

  1. Das Haupt Layout die ExpandableListView
  2. Die Gruppe Artikel Layout
  3. Das Kind Artikel Layout
  4. Der Header des Kindes Ansicht enthält.

Der Trick ist, die erste Reihe zu bekommen und als Header gesetzt:

public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) { 
    ParentObject currentParent = getGroup(groupPosition); 
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    //The first row is used as header 
    if(childPosition == 0){ 
     view = inflater.inflate(R.layout.child_header, null); 
     TextView txtHeader = (TextView)view.findViewById(R.id.txtHeader); 
     txtHeader.setText(currentParent.textToHeader); 
    } 

    //Fix the prior out of bound exception 
    if(childPosition > 0 &&* childPosition < getChildrenCount(groupPosition) - 1){ 
     ChildObject currentChild = getChild(groupPosition, childPosition - 1); 
     view = inflater.inflate(R.layout.child_row, null); 

     //Set your fields for the header here... i.e 
     TextView txtChildName = (TextView)view.findViewById(R.id.txtChildName); 
     TextView txtChildAge = (TextView)view.findViewById(R.id.txtChildAge); 
    } 

    return view; 
} 

Dann getChildrenCount() Rückkehr von 1, für die eine zur Aufnahme des benutzerdefinierten Adapters erhöhen wir für den Header verwenden.Wie folgt aus:

@override 
public int getChildrenCount(int i){ 
    return yourModel.get(i).childObjects.size() + 1; 
} 

Layout-es hält insgesamt

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <ExpandableListView 
     android:id="@+id/elv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"></ExpandableListView> 

</RelativeLayout> 

Layout für die Eltern Reihen

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:background="@color/parent_background" 
    android:paddingLeft="@dimen/padding_left" 
    android:layout_margin="5dp" 
    android:layout_height="match_parent"> 
    <TextView 
     android:id="@+id/txtMother" 
     android:layout_marginTop="10dp" 
     android:textStyle="bold" 
     android:layout_marginBottom="5dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:id="@+id/txtFather" 
     android:layout_marginBottom="10dp" 
     android:textStyle="bold" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

Layout für die Kinder Row

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:background="@color/child_background" 
    android:paddingLeft="@dimen/padding_left" 
    android:layout_height="match_parent"> 
    <TextView 
     android:id="@+id/txtChildName" 
     android:textColor="@android:color/holo_orange_dark" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp"/> 
    <TextView 
     android:id="@+id/txtChildAge" 
     android:textColor="@android:color/holo_orange_dark" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp"/> 
</LinearLayout> 

-Layout für das Kopf

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:background="@color/hf_background" 
    android:paddingLeft="@dimen/padding_left"> 
<TextView 
    android:id="@+id/txtHeader" 
    android:textColor="@android:color/holo_green_light" 
    android:layout_width="match_parent" 
    android:gravity="center_vertical" 
    android:textStyle="bold" 
    android:text="Header" 
    android:layout_height="50dp" /> 
</LinearLayout> 
+0

Thx Dayan ich werde es versuchen jetzt –

+0

Super schnelle, korrekte und zuverlässige Antwort! Vielen Dank Sehr geehrte @Dayan –

+0

@MahdiHraybi Sie sind sehr willkommen – Dayan

Verwandte Themen