标签:pull-to-refresh android android-listview listadapter
我正在尝试在我的应用中实现chrisbanes’s Android-PullToRefresh.
但到目前为止,我所得到的只是一个空洞的看法.
如果我将ListView更改为Android小部件它工作正常,如果我使用PullToRefreshListView列表显示为空.
我正在使用自定义ListAdapter.
这是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="match_parent"
android:background="@color/white"
android:orientation="vertical" >
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/listview_jogos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null" >
</com.handmark.pulltorefresh.library.PullToRefreshListView>
</LinearLayout>
这是活动中的代码(至少根据调试信息调用它):
private void constroiLista(ArrayList<Jogo> lista)
{
PullToRefreshListView lv = (PullToRefreshListView)findViewById(R.id.listview_jogos);
if(lv != null && lista != null)
{
lv.setAdapter(new ListAdapter(this, lista));
lv.setOnRefreshListener(new OnRefreshListener<ListView>()
{
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView)
{
(dnt = new DownloadJogosTask()).execute();
}
});
// Call onRefreshComplete when the list has been refreshed.
lv.onRefreshComplete();
}
}
如果它有所不同,则包含此列表视图的布局将被扩展为基础布局:
((LinearLayout)findViewById(R.id.ll_base_layout)).addView(View.inflate(this, R.layout.lista_jogos, null));
是否有与此库相关的已知错误?我四处搜索但没有找到类似的东西.在此先感谢您的帮助 :)
解决方法:
在尝试了Tarek的建议后,我注意到PullToRefreshListView的高度始终为0.
如果我使用setContentView来设置布局而不是将其膨胀到另一个..它可以工作或者如果我设置一个固定的高度新的LayoutParams(LayoutParams.MATCH_PARENT,1000)
搞乱之后我最终在我的customOnCreate方法上添加了这段代码以使其工作:
((LinearLayout)findViewById(R.id.ll_base_layout)).addView(View.inflate(this, R.layout.lista_jogos, null));
LinearLayout ll = (LinearLayout)findViewById(R.id.ll_jogos);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)ll.getLayoutParams();
params.weight = 1;
ll.setLayoutParams(params);
谢谢你的帮助 :)
标签:pull-to-refresh,android,android-listview,listadapter 来源: https://codeday.me/bug/20190723/1509393.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。