AAkira/ExpandableLayout

Expandable Relative Layout not shows data in recyclerView got from server

Hayk985 opened this issue · 1 comments

Hi. In my expandableRelativeLayout I have a recyclerView and when I click, it expands and shows the recyclerView. In that recyclerView there is user comments. So when I give comments directly (ex. comment1, comment2) and then set the adapter it works good and after expand it shows the recyclerView with comments. But when I'm doing request to server (I'm using retrofit 2) and got comments from server and then set it to recyclerView, after expand it shows nothing. So I tried remove the expandableRelativeLayout and left only the recyclerView without any expand. And it showed the data from server. So the problem is in expandableRelativeLayout. Any idea?

Here is the code.

`public class CommentsPage extends BaseFragment {

private View mainView;
private ExpandableRelativeLayout relativeLayout;
private RecyclerView recyclerView;
private TextView showComments, commentCount;
private StatusRecyclerAdapter adapter;
private ApiClient apiClient;
private UserCommentData[] userCommentData;
private ArrayList<String> comments;
private ArrayList<Integer> realCommentId;
private LinearLayoutManager linearLayoutManager;
private static final String bundleUserId = "personUserIdBundle";

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainView = inflater.inflate(R.layout.person_page, container, false);
    apiClient = ApiClient.getInstance();
    
    comments = new ArrayList<>();
    realCommentId = new ArrayList<>();

    recyclerView = (RecyclerView) mainView.findViewById(R.id.rvAnimals);
    linearLayoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(linearLayoutManager);

    Bundle bundle = getArguments();
    
    if (bundle != null) {
        getUserComments(bundle.getString(bundleUserId));
    }

    showComments = (TextView) mainView.findViewById(R.id.showComments);
    commentCount = (TextView) mainView.findViewById(R.id.commentCount);
    relativeLayout = (ExpandableRelativeLayout) mainView.findViewById(R.id.expandableLayout1);

    showComments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            relativeLayout.toggle();
            if (relativeLayout.isExpanded()) {
                showComments.setText("Show all comments");
            } else {
                showComments.setText("Hide all comments");
            }
        }
    });

    return mainView;
}

public void getUserComments(String clientId) {
    Call<UserCommentData[]> getComments = apiClient.getComment(clientId);
    getComments.enqueue(new Callback<UserCommentData[]>() {
        @Override
        public void onResponse(Call<UserCommentData[]> call, Response<UserCommentData[]> response) {
            if (response.isSuccessful()) {
                userCommentData = response.body();

                for (int i = 0; i < userCommentData.length; i++) {
                    comments.add(response.body()[i].getText());
                    realCommentId.add(response.body()[i].getRealCommentId());
                }

                commentCount.setText(Integer.toString(comments.size()));
                adapter = new StatusRecyclerAdapter(getActivity(), comments);
                recyclerView.setAdapter(adapter);

                adapter.setClickListener(new StatusRecyclerAdapter.ItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Toast.makeText(getActivity(), "Comment " + Integer.toString(position + 1), Toast.LENGTH_SHORT).show();
                    }
                });


            } else {
                Toast.makeText(context, "Something went wrong", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Call<UserCommentData[]> call, Throwable t) {
            Toast.makeText(context, "An error occurred", Toast.LENGTH_SHORT).show();
        }
    });
}

}
`

The issue was in library version. I used version 1.4.2 and after upgrading to 1.6.0 it worked))