package com.lzx.demo.ui; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import com.github.jdsjlzx.recyclerview.LRecyclerView; import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter; import com.lzx.demo.R; import com.lzx.demo.adapter.DataAdapter; import com.lzx.demo.bean.ItemModel; import com.lzx.demo.util.TLog; import java.util.ArrayList; /** * * No data RecyclerView */ public class EmptyViewActivity extends AppCompatActivity { private LRecyclerView mRecyclerView = null; private DataAdapter mDataAdapter = null; private LRecyclerViewAdapter mLRecyclerViewAdapter = null; private View mEmptyView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_emptyview); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); mEmptyView = findViewById(R.id.empty_view); mRecyclerView.setEmptyView(mEmptyView);//设置在setAdapter之前才能生效 ArrayList<ItemModel> dataList = new ArrayList<>(); mDataAdapter = new DataAdapter(this); mDataAdapter.setDataList(dataList); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setPullRefreshEnabled(false); mEmptyView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //TODO 请求数据 TLog.error("refresh data"); ArrayList<ItemModel> dataList = new ArrayList<>(); for (int i = 0; i < 10; i++) { ItemModel itemModel = new ItemModel(); itemModel.title = "item" + i; dataList.add(itemModel); } mDataAdapter.setDataList(dataList); } }); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { finish(); } return true; } }