0

I am getting data from TMDB API and displaying it on screen.

Right now, I am trying to get reviews from that API.

Everything seems fine, I created: adapter,model,interface,xml and activities, but it is not displaying any data.

API is working fine, I can see from Android Monitor that I am getting right data.

Somebody help, please.

Bellow is my DetailsActivity where I am trying to fetch data:

public class MovieDetailActivity extends AppCompatActivity {
public static final String EXTRA_MOVIE = "EXTRA_MOVIE";
private Movie mMovie;
private Reviews mReviews;
private Genres mGenres;
public ReviewAdapter rAdapter;

ImageView backdrop;
ImageView poster;
TextView title;
TextView description;
TextView releaseDate;
TextView voteAverage;
RecyclerView reviews;
TextView content;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie_detail);
    if (getIntent().hasExtra(EXTRA_MOVIE)) {
        mMovie = getIntent().getParcelableExtra(EXTRA_MOVIE);
    } else {
        throw new IllegalArgumentException("Detail activity must receive a movie parcelable");
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
    toolbarLayout.setTitle(mMovie.getTitle());


    reviews = (RecyclerView) findViewById(R.id.recyclerView2);
    reviews.setLayoutManager(new LinearLayoutManager(this));
    rAdapter = new ReviewAdapter(MovieDetailActivity.this);

    reviews.setAdapter(rAdapter);


    getReviews(mMovie.getId());




    poster = (ImageView) findViewById(R.id.movie_poster);
    String internetUrl = "http://image.tmdb.org/t/p/w500";

    Glide.with(this)
            .load(mMovie.getPoster())
            .into(poster);

    Glide.with(this)
            .load(mMovie.getBackdrop())
            .into(backdrop);
}


private void getReviews(Integer id) {
    RestAdapter.getMovieService().getReviews(id, new Callback<ReviewWraper>() {
        @Override
        public void success(ReviewWraper reviewWraper, Response response) {
            rAdapter.setReviewList(reviewWraper.getResults());
        }

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

        }
    });
}

public static class MovieViewHolder extends RecyclerView.ViewHolder {

    public ImageView reviewPicture;
    public TextView reviewUsername;
    public TextView reviewDate;
    public TextView reviewTime;
    public TextView reviewComment;


    public MovieViewHolder(View itemView) {
        super(itemView);

        reviewPicture = (ImageView) itemView.findViewById(R.id.picture_review);
        reviewUsername = (TextView) itemView.findViewById(R.id.username_review);
        reviewDate = (TextView) itemView.findViewById(R.id.date_review);
        reviewTime = (TextView) itemView.findViewById(R.id.time_review);
        reviewComment = (TextView) itemView.findViewById(R.id.review_comment);



    }
}

Here is my adapter class:

public class ReviewAdapter extends RecyclerView.Adapter<MovieDetailActivity.MovieViewHolder> {

private List<Reviews> rReviewList;
private LayoutInflater rInflater;
private Context rContext;

public ReviewAdapter(Context context) {
    this.rContext = context;
    this.rInflater = LayoutInflater.from(context);
    this.rReviewList = new ArrayList<>();
}


public MovieDetailActivity.MovieViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
    // create a new view
    View view = rInflater.inflate(R.layout.row_review, parent, false);
    return new MovieDetailActivity.MovieViewHolder(view);
}

@Override
public void onBindViewHolder(MovieDetailActivity.MovieViewHolder holder, int position) {
    Reviews reviews = rReviewList.get(position);
    Picasso.with(rContext)
            .load(reviews.getUrl())
            .into(holder.reviewPicture);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Perform click
        }
    });
}


@Override
public int getItemCount() {
    return rReviewList.size();
}

//To update data
public void setReviewList(List<Reviews> reviewsList) {
    this.rReviewList = new ArrayList<>();
    this.rReviewList.addAll(reviewsList);
    notifyDataSetChanged();
}

Bellow is XML 1:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content"
    android:layout_height="wrap_content">



   <ImageView
       android:id="@+id/picture_review"
       android:layout_width="50dp"
       android:layout_height="50dp" />

    <TextView
        android:adjustViewBounds="true"
        android:id="@+id/username_review"
        android:layout_width="40dp"
        android:layout_height="20dp"
        android:width="20dp"
        android:height="20dp"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/date_review"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/time_review"
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/review_comment"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:textColor="#ffffff"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/picture_review"
        android:layout_toEndOf="@+id/picture_review" />

</RelativeLayout>

And XML 2 with RecyclerView

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.demo.mtin.mtin.MovieDetailActivity"
    tools:showIn="@layout/activity_movie_detail">

                <android.support.v7.widget.RecyclerView

                    android:id="@+id/recyclerView2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textColor="#ffffff" />
J.range
  • 449
  • 5
  • 20
  • @Meet Do you have any idea? thanks – J.range May 19 '16 at 21:42
  • Not sure it is your issue, but you aren't going to want a RecyclerView inside of a ScrollView of any sort. – zgc7009 May 19 '16 at 21:44
  • @zgc7009 It is not problem,but thanks:) – J.range May 19 '16 at 21:49
  • http://stackoverflow.com/questions/31000081/how-to-use-recyclerview-inside-nestedscrollview I still, however, recommend taking Adapter backed Views out of ScrollViews. – zgc7009 May 19 '16 at 21:51
  • I have to use it inside of this.Can not just change ScrollView with RecyclerView.Do you have any alternative ways to put Recycler somwhere else? – J.range May 19 '16 at 21:59
  • You can use `recyclerView.setNestedScrollingEnabled(false);` in code for the scrolling issue. Also you could benefit from adding a place holder image that'll be used before loading the url with `Picasso`. i.e. just add to the Picasso builder `.placeholder(R.drawable.user_placeholder)`. – ade.akinyede May 19 '16 at 22:02
  • @ade.akinyede Thanks but it is not helping me, there is no problem with scrolling – J.range May 19 '16 at 22:10
  • try setting on NestedScrollview: android:fillViewport="true" – khusrav May 19 '16 at 22:12
  • @khusrav not helping,but thank you – J.range May 19 '16 at 22:14
  • Don't know if it affects, but you need to change RelativeLayout to LinearLayout with orientation="vertical" or put appropriate orientation attributes to the views within RelativeLayout. I'd try the 1st one first to see if it's the problem – khusrav May 19 '16 at 22:19
  • Anyway, copied to my local project - should not be the issue, at least would show anything – khusrav May 19 '16 at 22:21
  • @khusrav still not working:/ – J.range May 19 '16 at 22:31

2 Answers2

0

Try to give fixed height instead of "wrap_content" on your row in root of Xml 1.

eralp
  • 113
  • 7
0
tools:showIn="@layout/activity_movie_detail">

If XML 2 needs to show in XML 1, XML1 must have this -

<include layout="@layout/XML2"/>

See this for more details - android-how-to-use-tools-with-include-layout

Community
  • 1
  • 1
a_m
  • 341
  • 5
  • 16