use of com.scwang.smartrefresh.layout.SmartRefreshLayout 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.smartrefresh.layout.SmartRefreshLayout in project AgentWeb by Justson.
the class SmartRefreshWebFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final SmartRefreshLayout mSmartRefreshLayout = (SmartRefreshLayout) this.mSmartRefreshWebLayout.getLayout();
final WebView mWebView = this.mSmartRefreshWebLayout.getWebView();
mSmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
mAgentWeb.getUrlLoader().reload();
mSmartRefreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
mSmartRefreshLayout.finishRefresh();
}
}, 2000);
}
});
mSmartRefreshLayout.autoRefresh();
}
Aggregations