0
我打算在第一頁製作網站應用程序和加載Feed,但問題是滾動是無止境的,如何阻止它?滾動是無止境的,所以我想停止它。如何在我的應用程序中停止無盡滾動?
public class FeedActivity extends AppCompatActivity
{
private SwipeRefreshLayout swipeLayout;
private RecyclerView listView;
private LinearLayoutManager layoutManager;
private FeedAdapter adapter;
private FeedService service;
private FeedModel model;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feed);
ActionBar actionBar = getSupportActionBar();
if(null != actionBar)
{
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.ic_launcher);
}
model = new FeedModel();
adapter = new FeedAdapter(model);
service = FeedService.create(model);
layoutManager = new LinearLayoutManager(this);
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
listView = (RecyclerView) findViewById(R.id.listView);
listView.setLayoutManager(layoutManager);
listView.setAdapter(adapter);
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
}
@Override
protected void onStart()
{
super.onStart();
model.subscribe(onDataChangedListener);
adapter.setOnItemClickListener(onItemClickListener);
swipeLayout.setOnRefreshListener(onRefreshListener);
service.fetchOlder();
}
@Override
protected void onStop()
{
super.onStop();
model.unSubscribe(onDataChangedListener);
adapter.setOnItemClickListener(null);
swipeLayout.setOnRefreshListener(null);
}
FeedModel.OnDataChangedListener onDataChangedListener = new FeedModel.OnDataChangedListener()
{
@Override
public void onFetchedAndAddedToTop(int count)
{
swipeLayout.setRefreshing(false);
adapter.notifyDataSetChanged();
}
@Override
public void onFetchedAndAddedToBottom(int count)
{
if(count == 0)
{
adapter.setFooterEnabled(false);
}
adapter.notifyDataSetChanged();
}
};
SwipeRefreshLayout.OnRefreshListener onRefreshListener = new SwipeRefreshLayout.OnRefreshListener()
{
@Override
public void onRefresh()
{
service.fetchNewer();
}
};
FeedAdapter.OnItemClickListener onItemClickListener = new FeedAdapter.OnItemClickListener()
{
@Override
public void onItemClick(View view)
{
int position = listView.getChildAdapterPosition(view);
FeedItem item = model.get(position);
Intent intent = new Intent(getApplicationContext(), PostActivity.class);
intent.putExtra("id", item.getId());
startActivity(intent);
// System.out.println("Click: "+item.getTitle());
}
};
}