Search code examples
androidlayoutbaseadapter

How to remove layout inflated in custom adapter


if (audioFileList.get(position).isLastItem()) {
    convertView = inflater.inflate(R.layout.fragment_sound_add_button, null);
return convertView;

how can I catch:

if(convertView== R.layout.fragment_sound_add_button) { 
    remove layout, inflate new layout
}

Solution

  • Try this

    Inside the layout file "Fragment_sound_add_button" add an id to the root.

    //Root of fragment_sound_add_button
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root_fragment_sound_add_button"        
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    </LinearLayout>
    

    Then inside your code check if your convertView contains this Id

    if (audioFileList.get(position).isLastItem()) {
       if(convertView.findViewById(R.id.root_fragmentn_sound_add_button) != null){ 
           //inflate the layout again
           convertView = inflater.inflate(R.layout.fragment_sound_add_button, null);
       } else {
          //convertView doesnt contain R.layout.fragmnt_sound_add_button
       }
       return convertView;
    }
    

    I hope this helps!