在我的Recycler View上需要无限滚动

时间:2016-05-17 14:06:57

标签: android

我现在正在将电影提供给我的MainActivity。

我需要在MainActivity中的RecycleView上进行无限滚动。 有人能告诉我在哪里设置代码,这样我可以有无限滚动吗?

如果您需要更多数据,请告诉我。

谢谢。

MainActivity Code如下:

public class MainActivity extends AppCompatActivity {

private RecyclerView mRecyclerView;
private MoviesAdapter mAdapter;



@Override
protected void onResume() {
    SharedPreferences sharedPref = getBaseContext().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    String order = sharedPref.getString("order", "popular");
    if (order.equals("popular")) {
        getPopularMovies();
    } else {
        getTopRatedMovies();
    }
    super.onResume();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // uci i postaviti order -> popular
    Log.d("NESTO", "NESTO-onCreate");
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);


    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    mAdapter = new MoviesAdapter(MainActivity.this);
    mRecyclerView.setAdapter(mAdapter);


}


private void getTopRatedMovies() {
    RestAdapter.getMovieService().getTopRatedMovies(new Callback<MovieResult>() {
        @Override
        public void success(MovieResult movieResult, Response response) {
            mAdapter.setMovieList(movieResult.getResults());
        }

        @Override
        public void failure(RetrofitError error) {
            error.printStackTrace();

        }
    });
}


private void getPopularMovies() {


    RestAdapter.getMovieService().getPopularMovies(new Callback<MovieResult>() {
        @Override
        public void success(MovieResult movieResult, Response response) {
            mAdapter.setMovieList(movieResult.getResults());
        }

        @Override
        public void failure(RetrofitError error) {
            error.printStackTrace();
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Intent intent = new Intent(this, SettingsActivity.class);
    startActivity(intent);

    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {


        return true;
    }

    return super.onOptionsItemSelected(item);
}


public static class MovieViewHolder extends RecyclerView.ViewHolder {
    public ImageView imageView;

    public MovieViewHolder(View itemView) {
        super(itemView);
        imageView = (ImageView) itemView.findViewById(R.id.imageView);
    }
}

}

0 个答案:

没有答案