Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java listfragment(listview)中的页脚_Java_Android_Listview - Fatal编程技术网

Java listfragment(listview)中的页脚

Java listfragment(listview)中的页脚,java,android,listview,Java,Android,Listview,我正在尝试为android的列表视图添加一个静态页脚。我正在使用一个列表片段,一个填充父级的列表视图,并从主活动加载它。我想在列表视图中添加一个页脚,因此我创建了一个页脚xml文件,但无法从列表片段中加载它。它要么崩溃,要么什么也没发生 在listfragment内的listview中加载静态页脚的正确代码是什么?在listfragment扩展类中粘贴时,我引用的任何代码片段都不起作用 当“viewpager布局参数无法强制转换为abslistviewlayoutparams”或类似的内容崩溃时

我正在尝试为android的列表视图添加一个静态页脚。我正在使用一个列表片段,一个填充父级的列表视图,并从主活动加载它。我想在列表视图中添加一个页脚,因此我创建了一个页脚xml文件,但无法从列表片段中加载它。它要么崩溃,要么什么也没发生

在listfragment内的listview中加载静态页脚的正确代码是什么?在listfragment扩展类中粘贴时,我引用的任何代码片段都不起作用

当“viewpager布局参数无法强制转换为abslistviewlayoutparams”或类似的内容崩溃时,我会出现此错误,viewpager是主父项,每个选项卡都是一个片段,其中一个片段是我试图添加页脚的listview

<!--This is the fragment with the list in it-->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone" 
        android:layout_centerInParent="true"
        />

     <include layout="@android:layout/list_content" />
     <ListView
          android:id="@+id/list"
          android:layout_height="wrap_content"
          android:layout_width="match_parent" />

</RelativeLayout>

谢谢。下面的代码我只是尝试、编译和运行,但什么也不做。它在房间里 onCreateView方法,它是一个扩展ListFragment的类

     lview = (ListView)view.findViewById(R.id.list);            

     //nothing happens using this    
     lview.addFooterView(
             inflater.inflate(R.layout.standalone_footer, null)
      );

      //crashes with cast exception using this
      lview.addFooterView(
             inflater.inflate(R.layout.standalone_footer, container, false)      
     );

//onCreate method, either crashes or runs but nothing happens when tweaking code
    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)        {

     View view = inflater.inflate(R.layout.fragment_tab1, container, false);

     lv = (ListView)view.findViewById(R.id.list);

     mItems = new ArrayList<ListViewCustom>();

     //add static fixed footer
     lv.addFooterView(
             inflater.inflate(R.layout.footer, null, false)     //also tried passing lv instead of null 
     );

     //initialize and set the list adapter
     setListAdapter(new ListViewAdapterCustom(getActivity(), mItems));

     return view;
}
lview=(ListView)view.findviewbyd(R.id.list);
//用这个什么都不会发生
lview.addFooterView(
充气器。充气(R.layout.standalone\u页脚,空)
);
//使用此
lview.addFooterView(
充气机。充气(右布局。独立的页脚,容器,假)
);
//onCreate方法会崩溃或运行,但在调整代码时不会发生任何事情
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
视图=充气机。充气(R.layout.fragment_tab1,容器,假);
lv=(ListView)view.findViewById(R.id.list);
mItems=新的ArrayList();
//添加静态固定页脚
lv.addFooterView(
充气器。充气(R.layout.footer,null,false)//还尝试传递lv而不是null
);
//初始化并设置列表适配器
setListAdapter(新ListViewAdapterCustom(getActivity(),mItems));
返回视图;
}
独立页脚xml(带有xmlns标记的TableLayout在这里不显示为代码…) android:stretchColumns=“*” android:background=“#000”>


PS Listfragment和实际列表加载并呈现良好,所有这些都正常工作。如果需要的话,我也在使用自定义适配器?

view=(ListView)view.findViewById(R.id.list)
我不理解这一部分--您的基本视图被称为
视图
(当您调用
视图.findViewById
时可以看到),但您也将您的
列表视图
称为
视图

onCreateView()方法中尝试此操作:

ListView lv = (ListView) view.findViewById(R.id.list);
lv.addFooterView(inflater.inflate(R.layout.standalone_footer, null));

或者尝试
getListView().addFooterView(充气器.充气(R.layout.standalone_footer,null))

请也添加布局。你能添加整个
onCreateView
方法吗?我会编辑文章以包含它。我想更多的解释是,我使用的是带选项卡的滑动视图,每个选项卡都是一个片段,其中一个选项卡是一个显示listview的listfragment,我正在尝试向listview添加一个页脚st在该代码段的上下文中,我理解这种混淆,因为传递到onCreateView中的参数也是一个视图。因此,您的代码只是将其重命名为lv,它没有改变任何内容,仍然不起作用。在本例中,它编译了,但什么都没有发生。我尝试加载的是一个表视图,如果没有,则其中包含页脚xml的表行这意味着任何事情。getListView()将导致空指针异常,它在onCreateView中未就绪,我必须使用我正在膨胀并将从该函数返回的视图。
ListView lv = (ListView) view.findViewById(R.id.list);
lv.addFooterView(inflater.inflate(R.layout.standalone_footer, null));