Android的加入页脚的ListView addFooterView()?Android、ListView、addFooterView

由网友(暖心女帝/逗比女王)分享简介:我有一个需要页脚项目的列表,以便您可以点击它,它会加载更多的项目到列表中的ListView活动。该列表支持我的SimpleAdapter背靠字符串的地图,将适配器设置之前,我做这个序添加页脚:mInflater.inflate(R.layout.list_load_more_row,NULL);TextView的页脚=...

我有一个需要页脚项目的列表,以便您可以点击它,它会加载更多的项目到列表中的ListView活动。该列表支持我的SimpleAdapter背靠字符串的地图,将适配器设置之前,我做这个序添加页脚:

  mInflater.inflate(R.layout.list_load_more_row,NULL);

TextView的页脚=(TextView中)findViewById(R.id.loadMore);

。getListView()addFooterView(页脚);

setListAdapter(ListViewHelper.getAdapterForContentList(mContent,本));
 

但是我在调​​试器收到这个异常

显示java.lang.NullPointerException android.widget.ListView.clearRecycledState(ListView.java:489) android.widget.ListView.resetList(ListView.java:476) android.widget.ListView.setAdapter(ListView.java:417)

请告诉我错了,我将如何去有关添加我的页脚列表?

的酶活性使用 list_load_more_row.xml:

 < TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID / loadMore
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:TEXTSIZE =17sp
        机器人:TEXTSTYLE =黑体
        机器人:文字颜色=#000000
        机器人:ellipsize =金字招牌
        机器人:marqueeRepeatLimit =marquee_forever
        机器人:重力=center_horizo​​ntal | center_vertical
        机器人:文本=@字符串/你好/>
 

解决方案

Alrighty㈣发现了一个解决我的问题,如果我做到这一点按预期工作:

 查看视图= mInflater.inflate(R.layout.list_load_more_row,NULL);

TextView的页脚=(TextView中)view.findViewById(R.id.loadMore);

。getListView()addFooterView(页脚);

setListAdapter(ListViewHelper.getAdapterForContentList(mContent,本));
 
为什么我excel加了页脚会这样

我猜是因为我把空的充气作为父参数,该视图还没有被添加到当前内容视图等mainActivity无法找到它,现在因为我明确地使用父认为,返回由充气找到它正在TextView的。

I have a ListView activity that needs a footer to the list of items so that you can click it and it would load more items into the list. The list is backed my an SimpleAdapter backed by a map of strings and before the adapter is set i do this inorder to add the footer:

mInflater.inflate(R.layout.list_load_more_row, null);

TextView footer = (TextView) findViewById(R.id.loadMore);

getListView().addFooterView(footer);

setListAdapter(ListViewHelper.getAdapterForContentList(mContent, this));

But Im getting this exception in the debugger

java.lang.NullPointerException android.widget.ListView.clearRecycledState(ListView.java:489) android.widget.ListView.resetList(ListView.java:476) android.widget.ListView.setAdapter(ListView.java:417)

Whats wrong and how would i go about adding my footer to the list?

[EDIT] the activity is using list_load_more_row.xml:

  <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/loadMore"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="17sp"
        android:textStyle="bold"
        android:textColor="#000000"  
        android:ellipsize="marquee"  
        android:marqueeRepeatLimit="marquee_forever"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/hello" />

解决方案

Alrighty Iv found a solution to my problem if i do this it works as intended:

View view = mInflater.inflate(R.layout.list_load_more_row, null);

TextView footer = (TextView) view.findViewById(R.id.loadMore);

getListView().addFooterView(footer);

setListAdapter(ListViewHelper.getAdapterForContentList(mContent, this));

I'm guessing that since I put null in the inflater as the parent parameter, the view has not been added to the current content view and so mainActivity is unable to find it and now since I am explicitly using the parent view that is returned by the inflater to find the TextView it is working.

阅读全文

相关推荐

最新文章