如何删除自定义适配器中膨胀的布局
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;
我怎样才能抓到:
if(convertView== R.layout.fragment_sound_add_button) {
remove layout, inflate new layout
}
试试这个
在布局文件中 "Fragment_sound_add_button" 添加一个 id 到根。
//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>
然后在你的代码中检查你的 convertView 是否包含这个 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;
}
希望对您有所帮助!
if (audioFileList.get(position).isLastItem()) {
convertView = inflater.inflate(R.layout.fragment_sound_add_button, null);
return convertView;
我怎样才能抓到:
if(convertView== R.layout.fragment_sound_add_button) {
remove layout, inflate new layout
}
试试这个
在布局文件中 "Fragment_sound_add_button" 添加一个 id 到根。
//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>
然后在你的代码中检查你的 convertView 是否包含这个 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;
}
希望对您有所帮助!