我正在尝试添加消息说没有数据并且从游标获取数据的回收视图为空我尝试了很多解决方案但没有任何效果这是主要活动:public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> { private static final String TAG = MainActivity.class.getSimpleName(); private static final int INVENTORY_LOADER_ID = 0; private CursorAdapter mAdapter; RecyclerView mRecyclerView; TextView emptyList; Cursor inventoryData; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRecyclerView = (RecyclerView) findViewById(R.id.inventories); emptyList = (TextView) findViewById(R.id.empty_list); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mAdapter = new CursorAdapter(this, this, this); mRecyclerView.setAdapter(mAdapter); getSupportLoaderManager().initLoader(INVENTORY_LOADER_ID, null, this); } @Override protected void onResume() { super.onResume(); getSupportLoaderManager().restartLoader(INVENTORY_LOADER_ID, null, this); } @Override public Loader<Cursor> onCreateLoader(int id, final Bundle loaderArgs) { return new AsyncTaskLoader<Cursor>(this) { Cursor inventoryData = null; @Override protected void onStartLoading() { if (inventoryData != null) { emptyList.setVisibility(View.GONE); deliverResult(inventoryData); } else { forceLoad(); } }
添加回答
举报
0/150
提交
取消