Android 使用PullToRefreshLayout时显示Listview标题
我指的是刷新Android 使用PullToRefreshLayout时显示Listview标题,android,listview,pull-to-refresh,Android,Listview,Pull To Refresh,我指的是刷新列表视图的教程 而且效果很好。但是问题是我在列表视图上面有一个布局,所以当我运行我的应用程序列表视图时,可以覆盖该布局。为了避免这种情况,我将该布局作为ListView的标题,但随后出现了一个新问题。当列表为空时,列表视图标题也不会显示。我还在适配器中使用了isEmpty(),但它仍然没有显示标题 类别: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(
列表视图的教程
而且效果很好。但是问题是我在列表视图
上面有一个布局
,所以当我运行我的应用程序列表视图
时,可以覆盖该布局
。为了避免这种情况,我将该布局作为ListView
的标题,但随后出现了一个新问题。当列表为空时,列表视图
标题
也不会显示。我还在适配器
中使用了isEmpty(),但它仍然没有显示标题
类别:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
activityView = layoutInflater.inflate(R.layout.groups_activity_layout, null, false);
setContentView(activityView);
/******************************************************************************/
ViewGroup viewGroup = (ViewGroup) activityView;
// As we're using a ListFragment we create a PullToRefreshLayout manually
mPullToRefreshLayout = new PullToRefreshLayout(ItemscreenActivity.this);
// We can now setup the PullToRefreshLayout
ActionBarPullToRefresh.from(this)
// We need to insert the PullToRefreshLayout into the Fragment's ViewGroup
.insertLayoutInto(viewGroup)
// Here we mark just the ListView and it's Empty View as pullable
.theseChildrenArePullable(R.id.listView_demo_Items_gsal, android.R.id.empty).listener(this).setup(mPullToRefreshLayout);
/******************************************************************************/
arrayListOfAItems.clear();
populateItemsArrayList(ItemscreenActivity.this);
ItemsListWrtCnt++;
// Getting the reference of Button and ListView
listViewOfItems = (ListView) findViewById(R.id.listView_demo_Items_gsal);
// Get Data in Adapter to set on ListView
ItemscreenActivityAdapter = new ItemscreenAdapter(ItemscreenActivity.this, R.layout.group_screen_adapter_layout, arrayListOfAItems);
listViewOfItems.setTextFilterEnabled(false);
listViewOfItems.setScrollingCacheEnabled(false);
listViewOfItems.setCacheColorHint(Color.TRANSPARENT);
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup) inflater.inflate(R.layout.group_activity_listview_header, listViewOfItems, false);
listViewOfItems.addHeaderView(header, null, false);
listViewOfItems.setEmptyView(header);
listViewOfItems.setVisibility(View.VISIBLE);
if (arrayListOfAItems.size() > 0) {
// Set Adapter to ListView of group if there are Items
ItemscreenActivityAdapter.notifyDataSetChanged();
listViewOfItems.setAdapter(ItemscreenActivityAdapter);
ItemsListWrtCnt--;
} else {
// Show Toast if no group to display
Toast.makeText(ItemscreenActivity.this, "No Items", Toast.LENGTH_SHORT).show();
}
}
XML:
您需要做的只是将适配器设置在if条件的一侧。作为:
if (arrayListOfAItems.size() > 0) {
// Set Adapter to ListView of group if there are Items
ItemscreenActivityAdapter.notifyDataSetChanged();
ItemsListWrtCnt--;
} else {
// Show Toast if no group to display
Toast.makeText(ItemscreenActivity.this, "No Items", Toast.LENGTH_SHORT).show();
}
listViewOfItems.setAdapter(ItemscreenActivityAdapter);
至于显示标题,您需要设置适配器的任何方式。
当您的列表为空时,适配器未设置,所以您无法看到标题
试试看。它肯定会工作。请发布您的xml文件代码。同时在列表视图中显示绑定数据的代码。@GrlsHu我添加了代码,请检查。@Akki尝试将此android:layout\u height=“wrap\u content”
更改为android:layout\u height=“match\u parent”
,看看是否有帮助(虽然没有尝试,但这是我的最佳猜测)@格里舒你看过我的照片了吗code@Akki根据添加一个假空视图如何?
if (arrayListOfAItems.size() > 0) {
// Set Adapter to ListView of group if there are Items
ItemscreenActivityAdapter.notifyDataSetChanged();
ItemsListWrtCnt--;
} else {
// Show Toast if no group to display
Toast.makeText(ItemscreenActivity.this, "No Items", Toast.LENGTH_SHORT).show();
}
listViewOfItems.setAdapter(ItemscreenActivityAdapter);