use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.
the class NestedLayoutExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_region);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(new BaseRecyclerAdapter<String>(Arrays.asList(provinces), android.R.layout.simple_list_item_1) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, String model, int position) {
holder.text(android.R.id.text1, model);
}
}.setOnItemClickListener(this));
}
/**
* 以下代码仅仅为了演示效果而已,不是必须的
* 关键代码在 activity_example_assign_xml 中
*/
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
if (isFirstEnter && refreshLayout != null) {
isFirstEnter = false;
// 触发上拉加载
refreshLayout.autoRefresh();
}
}
use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.
the class SnapHelperExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_snaphelper);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
// 初始化列表和监听
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(new BaseRecyclerAdapter<Integer>(loadModels(), R.layout.listitem_example_snaphelper) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Integer model, int position) {
holder.image(R.id.imageView, model);
}
});
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
}
}
use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.
the class BezierRadarStyleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_bezier);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
mRefreshHeader = (BezierRadarHeader) findViewById(R.id.header);
if (isFirstEnter) {
isFirstEnter = false;
// 第一次进入触发自动刷新,演示效果
mRefreshLayout.autoRefresh();
}
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
}
}
use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.
the class BasicExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_basic);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
AbsListView listView = (AbsListView) findViewById(R.id.listView);
listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(simple_list_item_2) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
mAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BottomSheetDialog dialog = new BottomSheetDialog(BasicExampleActivity.this);
View dialogView = View.inflate(BasicExampleActivity.this, R.layout.activity_example_basic, null);
dialog.setContentView(dialogView);
AbsListView listView = (AbsListView) dialogView.findViewById(R.id.listView);
listView.setAdapter(mAdapter);
ViewGroup parentGroup = (ViewGroup) listView.getParent();
parentGroup.removeView(listView);
// ViewGroup parentRoot = (ViewGroup) parentGroup.getParent();
// parentRoot.removeView(parentGroup);
RecyclerView recyclerView = new RecyclerView(BasicExampleActivity.this);
recyclerView.setLayoutManager(new LinearLayoutManager(BasicExampleActivity.this));
recyclerView.setAdapter(mAdapter);
((SmartRefreshLayout) parentGroup).setEnableRefresh(false);
// ((SmartRefreshLayout) parentGroup).startNestedScroll(0);
// ((SmartRefreshLayout) parentGroup).setEnableOverScrollDrag(false);
((SmartRefreshLayout) parentGroup).setRefreshContent(recyclerView);
// parentRoot.addView(recyclerView, -1, -1);
dialog.show();
}
});
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
// 开启自动加载功能(非必须)
refreshLayout.setEnableAutoLoadMore(true);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.refresh(initData());
refreshLayout.finishRefresh();
refreshLayout.setNoMoreData(false);
}
}, 2000);
}
});
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
if (mAdapter.getItemCount() > 30) {
Toast.makeText(getApplication(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
// 将不会再次触发加载更多事件
refreshLayout.finishLoadMoreWithNoMoreData();
} else {
mAdapter.loadMore(initData());
refreshLayout.finishLoadMore();
}
}
}, 2000);
}
});
// 触发自动刷新
refreshLayout.autoRefresh();
}
use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.
the class CustomExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_custom);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(simple_list_item_2) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.refresh(initData());
refreshLayout.finishRefresh();
}
}, 2000);
}
});
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setHeaderHeight(60);
// 触发自动刷新
if (isFirstEnter) {
isFirstEnter = false;
refreshLayout.autoRefresh();
} else {
mAdapter.refresh(initData());
}
}
Aggregations