ListFragment does not accept my layout

前端 未结 10 1356
情歌与酒
情歌与酒 2020-12-01 02:09

According to this link: ListFragment android developers

I want to set my custom layout for list, but it makes exceptions.

Here is the code:

p         


        
10条回答
  •  抹茶落季
    2020-12-01 02:56

    I just needed to change my empty text TextView properties and did this

    @Override
    public void onLoadFinished(Loader loader, Cursor cursor) {
        // Swap the new cursor in. (The framework will take care of closing the
        // old cursor once we return)
        mAdapter.swapCursor(cursor);
        if (cursor.getCount() == 0) {
            setEmptyText(getString(R.string.no_users));
            TextView tvEmpty = (TextView) getListView().getEmptyView();
            tvEmpty.setTextColor(getResources().getColor(R.color.blue));
        }
        // The list should now be shown.
        if (isResumed()) {
            setListShown(true);
        } else {
            setListShownNoAnimation(true);
        }
    }
    

    Do not forget that if you try initializing tvEmpty before you call setEmptyText("Empty"), you'll run into a NullPointerException

提交回复
热议问题