use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.
the class AutoLoadMoreActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_auto_load_more);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new AutoLoadAdapter(this);
recyclerView.setAdapter(mAdapter);
final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
mAdapter.setAlwaysShowHead(true);
mAdapter.setAlwaysShowFoot(true);
mAdapter.addHeadLayout(R.layout.item_head);
mAdapter.addFootLayout(R.layout.item_foot2);
// 模拟数据
data = new ArrayList<>();
for (int i = 0; i < mTitles.length; i++) {
ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
data.add(card);
}
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// 模拟刷新
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.setRefreshing(false);
mAdapter.setData(data);
}
}, 500);
}
});
// 必须设置事件监听与开启auto
mAdapter.openAutoLoadMore(true);
mAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore() {
Log.d("Sherlock", "加载更多");
// 模拟加载更多
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if (mState == LOAD_ADD) {
mAdapter.addData(data);
} else if (mState == LOAD_COMPLETED) {
mAdapter.loadCompleted();
} else if (mState == LOAD_FAILED) {
mAdapter.loadFailed();
}
}
}, 800);
}
});
findViewById(R.id.action_add).setOnClickListener(this);
findViewById(R.id.action_failed).setOnClickListener(this);
findViewById(R.id.action_completed).setOnClickListener(this);
findViewById(R.id.action_empty).setOnClickListener(this);
findViewById(R.id.action_close).setOnClickListener(this);
mShowHead = (CheckBox) findViewById(R.id.cb_show_head);
mShowFoot = (CheckBox) findViewById(R.id.cb_show_foot);
mShowHead.setChecked(true);
mShowFoot.setChecked(true);
mShowHead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mAdapter.setAlwaysShowHead(isChecked);
}
});
mShowFoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mAdapter.setAlwaysShowFoot(isChecked);
}
});
}
use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.
the class HeadAndFootActivity method refresh.
private void refresh() {
if (mChangeOrder) {
List<ImageCard> data = new ArrayList<>();
for (int i = mTitles.length - 1; i >= 0; i--) {
ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
data.add(card);
}
mAdapter.setData(data);
} else {
List<ImageCard> data = new ArrayList<>();
for (int i = 0; i < mTitles.length; i++) {
ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
data.add(card);
}
mAdapter.setData(data);
}
mChangeOrder = !mChangeOrder;
}
use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.
the class ExpandableActivity method initData.
private void initData() {
int width = getResources().getDisplayMetrics().widthPixels / mStaggeredGridLayoutManager.getSpanCount();
List<IMultiItem> data = new ArrayList<>();
for (int i = 0; i < mLabels.length; i++) {
ImageLabel label = new ImageLabel(mLabels[i]);
data.add(label);
}
// Add animals
List<IMultiItem> animalData = new ArrayList<>(2);
for (int i = 0; i < mAnimalIds.length; i++) {
ImageCard cardData = new ImageCard(mAnimalIds[i], mAnimalTitles[i]);
Card card = new Card(width, cardData);
animalData.add(card);
}
((DefaultExpandable) data.get(0)).addSubData(animalData);
// Add beauties
List<IMultiItem> beautyData = new ArrayList<>(mBeautyIds.length);
for (int i = 0; i < mBeautyIds.length; i++) {
ImageCard cardData = new ImageCard(mBeautyIds[i], mBeautyTitles[i]);
Card card = new Card(width, cardData);
beautyData.add(card);
}
((DefaultExpandable) data.get(1)).addSubData(beautyData);
// Add scenery
List<IMultiItem> sceneryData = new ArrayList<>(mSceneryIds.length);
for (int i = 0; i < mSceneryIds.length; i++) {
ImageCard cardData = new ImageCard(mSceneryIds[i], mSceneryTitles[i]);
Card card = new Card(width, cardData);
sceneryData.add(card);
}
((DefaultExpandable) data.get(2)).addSubData(sceneryData);
// Add tranquil
List<IMultiItem> tranquilData = new ArrayList<>(mTranquilIds.length);
for (int i = 0; i < mTranquilIds.length; i++) {
ImageCard cardData = new ImageCard(mTranquilIds[i], mTranquilTitles[i]);
Card card = new Card(width, cardData);
tranquilData.add(card);
}
((DefaultExpandable) data.get(3)).addSubData(tranquilData);
mAdapter.setData(data);
}
use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.
the class HeadAndFootActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_head_and_foot);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new HeadAndFootAdapter(this);
recyclerView.setAdapter(mAdapter);
mAdapter.addHeadLayout(R.layout.item_head);
mAdapter.addFootLayout(R.layout.item_foot);
mAdapter.addFootLayout(R.layout.item_foot2);
List<ImageCard> data = new ArrayList<>();
for (int i = 0; i < mTitles.length; i++) {
ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
data.add(card);
}
mAdapter.setData(data);
final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refresh();
refresh.setRefreshing(false);
}
});
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
refresh();
}
});
}
Aggregations