I am trying to inflate the custom layout inside the OnBindViewHolder of recyclerview. I could inflate the layout and add the view with for loop successfully to the LinearLayout which is the viewgroup of recyclerview's item, but I cannot set the values to the TextViews of the inflated layout. Here is what I tried so far.Any small hint would be helpful.
@Override
public void onBindViewHolder(ParentViewHolder holder, int position) {
holder.title.setText(dataModels.get(position).getTopic());
listModels = dataModels.get(position).getBreakingAndLatestNewsListModels();
View.OnClickListener myListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String tag = (String) v.getTag();
Toast.makeText(context, listModels.get(Integer.parseInt(tag)).getTitle(), Toast.LENGTH_SHORT).show();
}
};
for (int i = 0; i < listModels.size(); i++) {
View v = inflater.inflate(R.layout.news_content_layout, holder.containerLayout, false);
v.setTag(i + "");
holder.containerLayout.addView(v);
v.setOnClickListener(myListener);
TextView titleTextView = (TextView) v.findViewById(R.id.news_title_text_view);
titleTextView.setText("jst testing");
}
}
The alternate way I tried this too, but again there is another ploblem in expanding and collapsing the toolbar