My need is That I am inflating JSON data in Recycler. okay. Now I want to put a indicator LIKE THIS STYLE that will show that how many items you have in RecyclerView. When one item has been readed or currently, Indicator will be heilighted and when use scroll down the its top selected position item will be heilighted.. Please help me how can I do this..
My Adapter Method
@Override
public MessageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_message, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(MessageAdapter.ViewHolder holder, int position) {
/*Tuesday, April 10, 2001 3:51 PM*/
msgModels = msgList.get(position);
if (msgList.get(position) != null) {
holder.msgTitle.setText(msgModels.getMessageTitle());
holder.msgDescription.setText(msgModels.getMessageDescription());
holder.msgDate.setText(msgModels.getMessageDate());
//
}
if (firstVisible==position) {
holder.msgTitle.setTextColor(Color.RED);
holder.msgDescription.setTextColor(Color.RED);
holder.msgDate.setTextColor(Color.RED);
holder.layerLyt.setAlpha(1);
}
if (position==msgList.size()-1) {
holder.msgTitle.setTextColor(Color.RED);
holder.msgDescription.setTextColor(Color.RED);
holder.msgDate.setTextColor(Color.RED);
holder.layerLyt.setAlpha(1);
}
else{
holder.msgTitle.setTextColor(Color.BLUE);
holder.msgDescription.setTextColor(Color.BLUE);
holder.msgDate.setTextColor(Color.BLUE);
holder.layerLyt.setAlpha(0.2f);
}
}
@Override
public int getItemCount() {
return msgList.size();
}
private int firstVisible = 0;
private int lastVisible ;
public void changeItem(int position){
firstVisible = position;
notifyItemChanged(firstVisible);
notifyDataSetChanged();
} public void changeLastItem(int position){
lastVisible = position;
notifyItemChanged(lastVisible);
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView msgTitle, msgDescription,msgDate;
public RelativeLayout layerLyt;
public ViewHolder(View view) {
super(view);
msgTitle = (TextView)view.findViewById(R.id.msgTitle);
msgDescription = (TextView)view.findViewById(R.id.msgDescription);
layerLyt = (RelativeLayout) view.findViewById(R.id.layerLyt);
msgDate = (TextView)view.findViewById(R.id.msgDate);
}
}
My Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_message, null);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_viewLaws);
linearLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setAdapter(msgAdapter);
msgAdapter = new MessageAdapter(msgList, getActivity(), this);
//msgAdapter.notifyDataSetChanged();
mProgressDialog = new ProgressDialog(getActivity());
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
int firstVisible = manager.findFirstVisibleItemPosition();
int lastVisible = manager.findLastVisibleItemPosition();
Log.i("TAG", "onScrolled: " + firstVisible);
Log.i("TAG", "Last Index: " + lastVisible);
msgAdapter.changeItem(firstVisible);
msgAdapter.changeLastItem(lastVisible);
}
});
if (NetworkCheck.getInstant(getActivity()).isConnectingToInternet()) {
loadAPI();
} else {
ErrorMessageDialog.getInstant(getActivity()).show("No Network");
}
return view;
}
private void loadAPI() {
mProgressDialog.setMessage("Loading...");
mProgressDialog.setCancelable(false);
mProgressDialog.show();
new PostStringRequest(getActivity(), setMessagePostBody(), this, API_MSG_CALL, NetworkUtility.MESSAGE_API);
}