2017-01-19 3 views
1

Ich versuche eine Liste von Elementen mit RecyclerView, alles funktioniert gut, aber das letzte Element wird nicht angezeigt! Die Länge der Liste ist und onBindView heißt zweimal und die, wenn ich Protokoll verwendete, um die Einzelteile zu drucken es druckt das letzte Einzelteil. Die Liste ist also in Ordnung, aber die RecyclerView zeigt sie nicht an.RecyclerView nicht letzten Artikel anzeigen, aber onBindView aufrufen

Dies ist mein Code RecyclerView Adapter:

public class ModuleList extends RecyclerView.Adapter<ModuleList.ViewHolder> { 

private List<Module> moduleList; 

public ModuleList(List<Module> moduleList){ 
    this.moduleList = moduleList; 

} 

public ModuleList(){ 
this.moduleList = new ArrayList<>(); 
} 

public List<Module> getModuleList() { 
    return moduleList; 
} 

public void setModuleList(List<Module> moduleList) { 
    this.moduleList = moduleList; 
} 

@Override 
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_modules,parent,false); 
    return new ViewHolder(view); 
} 

@Override 
public void onBindViewHolder(ViewHolder holder, int position) { 
      Module module = moduleList.get(position); 
     // function is called twice and the all items are logged works fine 
      Log.d("ALL",module.getModuleName()); 
      Log.d("ALL", String.valueOf(module.getNumberOfLevels())); 

      holder.moduleName.setText(String.valueOf(module.getModuleName())); 
      holder.numberOfLevels.setText(String.valueOf(module.getNumberOfLevels())); 


} 

@Override 
public int getItemCount() { 
    //size is 2 
    return moduleList.size(); 

} 

public class ViewHolder extends RecyclerView.ViewHolder{ 
     public TextView moduleName; 
     public TextView numberOfLevels; 


    public ViewHolder(View itemView) { 
     super(itemView); 
     moduleName = (TextView) itemView.findViewById(R.id.list_module_name); 
     numberOfLevels = (TextView) itemView.findViewById(R.id.list_no_of_levels); 
    } 
    } 
} 

Das ist mein xml wo recyclerview ist:

 <?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="match_parent"> 


     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/all_modules_list" 
      android:scrollbars="vertical" 

      /> 

    </LinearLayout> 

Das ist mein xml ist, wo RecyclerView Fragment angezeigt:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 

    android:id="@+id/main_screen" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:fitsSystemWindows="true" 

    > 





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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/main_screen_toolbar" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/fragment_container"> 


     </FrameLayout> 

    </LinearLayout> 


    <ListView 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:id="@+id/navigation_items" 
     android:layout_gravity="start" 
     android:background="@android:color/white" 
     > 

    </ListView> 



</android.support.v4.widget.DrawerLayout> 

Bearbeiten: list_module.xml

<?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="match_parent"> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/list_module_name" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/list_no_of_levels" 

     /> 


</LinearLayout> 
+0

in dem Gerät, das Sie diese –

+0

auf meinem Handy laufen nicht auf Emulator – Jois

+0

ich meine, das Telefon können Sie s angeben, dass ich Ihnen helfen kann, –

Antwort

0

Hey, kannst du die folgende Lösung versuchen?

Ändern Sie diese in der list_module.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/list_module_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/list_no_of_levels" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

Ich habe match_parent-wrap_content Mutter Layout ersetzt.

+0

Nein, ich habe die Soulution gefunden! Alles, was ich getan habe, war dieses 'android: fitsSystemWindows =" true "' von drawerLayout zu entfernen – Jois

Verwandte Themen