I am creating calenderview. and want to add multiple days events like google calender app so in this I am adding event at each day.I want to add one textview to linearlayout at position 2.at position 0 and 1 there is no any views are added, this is my code to insert view.
`
TextView tv = new TextView(context);
tv.setBackgroundResource(R.drawable.event_view);
int height
=context.getResources().getDimensionPixelSize(R.dimen.event_image_size);
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
int previousViewPosition = AppConstants.eventList.get(i-1).getEvent_count();
AppConstants.eventList.get(i).setEvent_count(previousViewPosition);
tv.setPadding(0, 0, 0, 0);
tv.setText(AppConstants.eventList.get(i).getStrName());
params.setMargins(0, 0, 0, 1);
tv.setLayoutParams(params);
tv.setTextSize(8);
tv.setTextColor(context.getResources().getColor(R.color.white));
ll_event_image.addView(tv, previousViewPosition);
`
it gives me error IndexOutOfBound.
05-02 11:57:17.162 8922-8922/com.calender.demo.calendar_api W/System.err: java.lang.IndexOutOfBoundsException: index=2 count=1 05-02 11:57:17.187 8922-8922/com.calender.demo.calendar_api W/System.err: at android.view.ViewGroup.addInArray(ViewGroup.java:4542) at android.view.ViewGroup.addViewInner(ViewGroup.java:4463) at android.view.ViewGroup.addView(ViewGroup.java:4218) 05-02 11:57:17.188 8922-8922/com.calender.demo.calendar_api W/System.err: at com.desai.vatsal.mydynamiccalendar.DateListAdapter$DateViewHolder.setDates(DateListAdapter.java:278) at com.desai.vatsal.mydynamiccalendar.DateListAdapter.onBindViewHolder(DateListAdapter.java:575) at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714) at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)