ViewPager not responding to touch in layout area created dynamically in Fragment












0















I'm trying to implement Viewpager with a calendar. I'm using the same three instances of the calendar Fragment for testing the ViewPager lets call the smooth motion of transferring one fragment to the next SWIPING. the swiping will not work in the area of the fragment that the layout was created dynamically in the fragment itself but the rest of page(above and below the date buttons)the swiping works great! here is some of the code the entire frag code would not fit so had to edit some declarations and button listener methods



// Main Activity




public class calenderview extends AppCompatActivity {
ArrayList<Fragment> fraglist;
ViewPager pager;
calenderviewpageradaptor adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calenderview);
fraglist = new ArrayList<>();
fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag());
adaptor = new calenderviewpageradaptor(getSupportFragmentManager(),fraglist);
pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adaptor);
}



public class calenderviewpageradaptor extends FragmentStatePagerAdapter {

ArrayList<Fragment> adaptorlist;
public calenderviewpageradaptor(FragmentManager fm,ArrayList<Fragment> list){
super (fm);
this.adaptorlist = list;
}

@Override
public int getCount(){
return 3;
}
@Override
public Fragment getItem(int pos){
return adaptorlist.get(pos);

}
}


}




public class Calview_frag extends Fragment {




    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);



    }
private LinearLayout.LayoutParams getdaysLayoutParams() {
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

buttonParams.weight = 1;

return buttonParams;

}
private void addDaysinCalendar(ViewGroup.LayoutParams buttonParams, DisplayMetrics metrics) {

int engDaysArrayCounter = 0;

LinearLayout.LayoutParams doitwithmarg = new LinearLayout.LayoutParams(120,120);
doitwithmarg.setMarginStart(cacmarg);
LinearLayout.LayoutParams doittoit = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,


ViewGroup.LayoutParams.WRAP_CONTENT);
doittoit.weight=1;



        for (int weekNumber = 0; weekNumber < 6; ++weekNumber) {

for (int dayInWeek = 0; dayInWeek < 7; ++dayInWeek) {

Button day = new Button(getContext());

day.setBackground(getResources().getDrawable(R.drawable.roundshapeclear));
day.setTextColor(getResources().getColor(R.color.GREY));
day.setBackgroundColor(Color.TRANSPARENT);
day.setTextSize((int) metrics.density *5 );
day.setSingleLine();

if(dayInWeek!=0){
day.setLayoutParams(doitwithmarg);
Space s = new Space(getContext());
s.setLayoutParams(doittoit);
weeks[weekNumber].addView(s);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                  else{
day.setLayoutParams(doitwithmarg);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                ++engDaysArrayCounter;

}

}

}
private void init(View view) {

DisplayMetrics metrics = getResources().getDisplayMetrics();

calendar = Calendar.getInstance();



weekOneLayout = (LinearLayout)view.findViewById(R.id.calendar_week_1);

weekTwoLayout = (LinearLayout)view.findViewById(R.id.calendar_week_2);

weekThreeLayout = (LinearLayout)view.findViewById(R.id.calendar_week_3);

weekFourLayout = (LinearLayout)view.findViewById(R.id.calendar_week_4);

weekFiveLayout = (LinearLayout)view.findViewById(R.id.calendar_week_5);

weekSixLayout = (LinearLayout)view.findViewById(R.id.calendar_week_6);

currentYear = (TextView)view.findViewById(R.id.current_date);

currentMonth = (TextView)view.findViewById(R.id.current_month);

currentDateDay = chosenDateDay = calendar.get(Calendar.DAY_OF_MONTH);



if (userMonth != 0 && userYear != 0) {

currentDateMonth = chosenDateMonth = userMonth;

currentDateYear = chosenDateYear = userYear;

} else {

currentDateMonth = chosenDateMonth = calendar.get(Calendar.MONTH);

currentDateYear = chosenDateYear = calendar.get(Calendar.YEAR);

}



currentYear.setText("" + chosenDateYear);

currentMonth.setText(ENG_MONTH_NAMES[currentDateMonth]);


initializeDaysWeeks();

if (userButtonParams != null) {

defaultButtonParams = userButtonParams;

} else {

defaultButtonParams = getdaysLayoutParams();

}

addDaysinCalendar(defaultButtonParams,metrics);



initCalendarWithDate(chosenDateYear, chosenDateMonth, chosenDateDay,view);



}



private void initializeDaysWeeks() {

weeks = new LinearLayout[6];

days = new Button[6 * 7];

weeks[0] = weekOneLayout;

weeks[1] = weekTwoLayout;

weeks[2] = weekThreeLayout;

weeks[3] = weekFourLayout;

weeks[4] = weekFiveLayout;

weeks[5] = weekSixLayout;

}
private void initCalendarWithDate(int year, int month, int day, View v) {

if (calendar == null)

calendar = Calendar.getInstance();

calendar.set(year, month, day);

int daysInCurrentMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);


chosenDateYear = year;

chosenDateMonth = month;

chosenDateDay = day;

calendar.set(year, month, 1);

int firstDayOfCurrentMonth = calendar.get(Calendar.DAY_OF_WEEK);

Log.d(tag,"FFFFFFiiiiiiiiiiirrrrrrrrrrsssssssssst day of month int"+firstDayOfCurrentMonth);

calendar.set(year, month, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Log.d(tag,"LLLLLLLLLLLLlaaaaasttttttttttt day of month int"+daysInCurrentMonth);

int dayNumber = 1;

int daysLeftInFirstWeek = 0;
firstDayOfCurrentMonth= firstDayOfCurrentMonth-1;
int indexOfDayAfterLastDayOfMonth = 0;

if (firstDayOfCurrentMonth != 0) {

daysLeftInFirstWeek = firstDayOfCurrentMonth;

indexOfDayAfterLastDayOfMonth = daysLeftInFirstWeek + daysInCurrentMonth;

> for (int i = firstDayOfCurrentMonth; i < firstDayOfCurrentMonth + daysInCurrentMonth; ++i) {
//checks all dates of calendar to set background and text colors
if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay){
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}
>
for (int i = 7; i < 7 + daysInCurrentMonth; ++i) {

if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay) {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshape));


days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}

}


//Displays previous and next month days



        if (month > 0)

calendar.set(year, month - 1, 1);

else

calendar.set(year - 1, 11, 1);

int daysInPreviousMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);



for (int i = daysLeftInFirstWeek - 1; i >= 0; --i) {

int dateArr = new int[3];



if (chosenDateMonth > 0) {

if (currentDateMonth == chosenDateMonth - 1

&& currentDateYear == chosenDateYear

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = chosenDateMonth - 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 11

&& currentDateYear == chosenDateYear - 1

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));


}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = 11;

dateArr[2] = chosenDateYear - 1;

}

days[i].setTag(dateArr);
days[i].setTextColor(getResources().getColor(R.color.GREY));;

days[i].setText("");

days[i].setOnClickListener(null);

}

int nextMonthDaysCounter = 1;

for (int i = indexOfDayAfterLastDayOfMonth; i < days.length; ++i) {

int dateArr = new int[3];


if (chosenDateMonth < 11) {

if (currentDateMonth == chosenDateMonth + 1

&& currentDateYear == chosenDateYear

&& nextMonthDaysCounter == currentDateDay) {

// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = chosenDateMonth + 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 0

&& currentDateYear == chosenDateYear + 1

&& nextMonthDaysCounter == currentDateDay) {
// selectedDayButton.setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
selectedDayButton.setTextColor(Color.WHITE);
// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);
} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = 0;

dateArr[2] = chosenDateYear + 1;

}

days[i].setTag(dateArr);

days[i].setText("");
days[i].setOnClickListener(null);
}

calendar.set(chosenDateYear, chosenDateMonth, chosenDateDay);
currentYear.setText(" " + chosenDateYear);
currentMonth.setText(ENG_MONTH_NAMES[chosenDateMonth]);


}



public Calview_frag() {//required empty constructor
}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layoutview = inflater.inflate(R.layout.fragment_calview,container,false);
but = (ImageButton)layoutview.findViewById(R.id.getitbutton);
fbut = (ImageButton)layoutview.findViewById(R.id.getit2button);
display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenheight = size.y;
screenwidth = size.x;
Log.d(tag,"sssssssssssccreen size "+screenwidth);
if(screenwidth<1300)
cacmarg = screenwidth/50;
else
cacmarg = screenwidth/25;
init(layoutview);
return layoutview;
}


}





<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/getitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_alignParentLeft="true"
android:src="@drawable/backbutton"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:gravity="center"

android:orientation="horizontal">

<TextView

android:id="@+id/current_month"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/bluegrey"

android:textSize="28sp" />


<TextView

android:id="@+id/current_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="4dp"

android:textColor="@color/bluegrey"

android:textSize="28sp" />

</LinearLayout>

<ImageButton
android:id="@+id/getit2button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/forwardbutton"
/>
</RelativeLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:weightSum="7">


<Button

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/sunday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/monday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/tuesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/wednesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/thursday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/friday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/saturday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


</LinearLayout>


<LinearLayout

android:id="@+id/calendar_week_1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_4"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_5"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_6"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" /> </LinearLayout>

</ScrollView>

</LinearLayout>












share|improve this question

























  • Please edit your question to better describe the issue, and to include your code for Calview_frag, and the relevant layouts.

    – Mike M.
    Nov 26 '18 at 1:11











  • ok mike here is some more code hope it helps

    – Jason
    Nov 26 '18 at 14:43
















0















I'm trying to implement Viewpager with a calendar. I'm using the same three instances of the calendar Fragment for testing the ViewPager lets call the smooth motion of transferring one fragment to the next SWIPING. the swiping will not work in the area of the fragment that the layout was created dynamically in the fragment itself but the rest of page(above and below the date buttons)the swiping works great! here is some of the code the entire frag code would not fit so had to edit some declarations and button listener methods



// Main Activity




public class calenderview extends AppCompatActivity {
ArrayList<Fragment> fraglist;
ViewPager pager;
calenderviewpageradaptor adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calenderview);
fraglist = new ArrayList<>();
fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag());
adaptor = new calenderviewpageradaptor(getSupportFragmentManager(),fraglist);
pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adaptor);
}



public class calenderviewpageradaptor extends FragmentStatePagerAdapter {

ArrayList<Fragment> adaptorlist;
public calenderviewpageradaptor(FragmentManager fm,ArrayList<Fragment> list){
super (fm);
this.adaptorlist = list;
}

@Override
public int getCount(){
return 3;
}
@Override
public Fragment getItem(int pos){
return adaptorlist.get(pos);

}
}


}




public class Calview_frag extends Fragment {




    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);



    }
private LinearLayout.LayoutParams getdaysLayoutParams() {
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

buttonParams.weight = 1;

return buttonParams;

}
private void addDaysinCalendar(ViewGroup.LayoutParams buttonParams, DisplayMetrics metrics) {

int engDaysArrayCounter = 0;

LinearLayout.LayoutParams doitwithmarg = new LinearLayout.LayoutParams(120,120);
doitwithmarg.setMarginStart(cacmarg);
LinearLayout.LayoutParams doittoit = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,


ViewGroup.LayoutParams.WRAP_CONTENT);
doittoit.weight=1;



        for (int weekNumber = 0; weekNumber < 6; ++weekNumber) {

for (int dayInWeek = 0; dayInWeek < 7; ++dayInWeek) {

Button day = new Button(getContext());

day.setBackground(getResources().getDrawable(R.drawable.roundshapeclear));
day.setTextColor(getResources().getColor(R.color.GREY));
day.setBackgroundColor(Color.TRANSPARENT);
day.setTextSize((int) metrics.density *5 );
day.setSingleLine();

if(dayInWeek!=0){
day.setLayoutParams(doitwithmarg);
Space s = new Space(getContext());
s.setLayoutParams(doittoit);
weeks[weekNumber].addView(s);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                  else{
day.setLayoutParams(doitwithmarg);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                ++engDaysArrayCounter;

}

}

}
private void init(View view) {

DisplayMetrics metrics = getResources().getDisplayMetrics();

calendar = Calendar.getInstance();



weekOneLayout = (LinearLayout)view.findViewById(R.id.calendar_week_1);

weekTwoLayout = (LinearLayout)view.findViewById(R.id.calendar_week_2);

weekThreeLayout = (LinearLayout)view.findViewById(R.id.calendar_week_3);

weekFourLayout = (LinearLayout)view.findViewById(R.id.calendar_week_4);

weekFiveLayout = (LinearLayout)view.findViewById(R.id.calendar_week_5);

weekSixLayout = (LinearLayout)view.findViewById(R.id.calendar_week_6);

currentYear = (TextView)view.findViewById(R.id.current_date);

currentMonth = (TextView)view.findViewById(R.id.current_month);

currentDateDay = chosenDateDay = calendar.get(Calendar.DAY_OF_MONTH);



if (userMonth != 0 && userYear != 0) {

currentDateMonth = chosenDateMonth = userMonth;

currentDateYear = chosenDateYear = userYear;

} else {

currentDateMonth = chosenDateMonth = calendar.get(Calendar.MONTH);

currentDateYear = chosenDateYear = calendar.get(Calendar.YEAR);

}



currentYear.setText("" + chosenDateYear);

currentMonth.setText(ENG_MONTH_NAMES[currentDateMonth]);


initializeDaysWeeks();

if (userButtonParams != null) {

defaultButtonParams = userButtonParams;

} else {

defaultButtonParams = getdaysLayoutParams();

}

addDaysinCalendar(defaultButtonParams,metrics);



initCalendarWithDate(chosenDateYear, chosenDateMonth, chosenDateDay,view);



}



private void initializeDaysWeeks() {

weeks = new LinearLayout[6];

days = new Button[6 * 7];

weeks[0] = weekOneLayout;

weeks[1] = weekTwoLayout;

weeks[2] = weekThreeLayout;

weeks[3] = weekFourLayout;

weeks[4] = weekFiveLayout;

weeks[5] = weekSixLayout;

}
private void initCalendarWithDate(int year, int month, int day, View v) {

if (calendar == null)

calendar = Calendar.getInstance();

calendar.set(year, month, day);

int daysInCurrentMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);


chosenDateYear = year;

chosenDateMonth = month;

chosenDateDay = day;

calendar.set(year, month, 1);

int firstDayOfCurrentMonth = calendar.get(Calendar.DAY_OF_WEEK);

Log.d(tag,"FFFFFFiiiiiiiiiiirrrrrrrrrrsssssssssst day of month int"+firstDayOfCurrentMonth);

calendar.set(year, month, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Log.d(tag,"LLLLLLLLLLLLlaaaaasttttttttttt day of month int"+daysInCurrentMonth);

int dayNumber = 1;

int daysLeftInFirstWeek = 0;
firstDayOfCurrentMonth= firstDayOfCurrentMonth-1;
int indexOfDayAfterLastDayOfMonth = 0;

if (firstDayOfCurrentMonth != 0) {

daysLeftInFirstWeek = firstDayOfCurrentMonth;

indexOfDayAfterLastDayOfMonth = daysLeftInFirstWeek + daysInCurrentMonth;

> for (int i = firstDayOfCurrentMonth; i < firstDayOfCurrentMonth + daysInCurrentMonth; ++i) {
//checks all dates of calendar to set background and text colors
if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay){
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}
>
for (int i = 7; i < 7 + daysInCurrentMonth; ++i) {

if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay) {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshape));


days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}

}


//Displays previous and next month days



        if (month > 0)

calendar.set(year, month - 1, 1);

else

calendar.set(year - 1, 11, 1);

int daysInPreviousMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);



for (int i = daysLeftInFirstWeek - 1; i >= 0; --i) {

int dateArr = new int[3];



if (chosenDateMonth > 0) {

if (currentDateMonth == chosenDateMonth - 1

&& currentDateYear == chosenDateYear

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = chosenDateMonth - 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 11

&& currentDateYear == chosenDateYear - 1

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));


}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = 11;

dateArr[2] = chosenDateYear - 1;

}

days[i].setTag(dateArr);
days[i].setTextColor(getResources().getColor(R.color.GREY));;

days[i].setText("");

days[i].setOnClickListener(null);

}

int nextMonthDaysCounter = 1;

for (int i = indexOfDayAfterLastDayOfMonth; i < days.length; ++i) {

int dateArr = new int[3];


if (chosenDateMonth < 11) {

if (currentDateMonth == chosenDateMonth + 1

&& currentDateYear == chosenDateYear

&& nextMonthDaysCounter == currentDateDay) {

// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = chosenDateMonth + 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 0

&& currentDateYear == chosenDateYear + 1

&& nextMonthDaysCounter == currentDateDay) {
// selectedDayButton.setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
selectedDayButton.setTextColor(Color.WHITE);
// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);
} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = 0;

dateArr[2] = chosenDateYear + 1;

}

days[i].setTag(dateArr);

days[i].setText("");
days[i].setOnClickListener(null);
}

calendar.set(chosenDateYear, chosenDateMonth, chosenDateDay);
currentYear.setText(" " + chosenDateYear);
currentMonth.setText(ENG_MONTH_NAMES[chosenDateMonth]);


}



public Calview_frag() {//required empty constructor
}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layoutview = inflater.inflate(R.layout.fragment_calview,container,false);
but = (ImageButton)layoutview.findViewById(R.id.getitbutton);
fbut = (ImageButton)layoutview.findViewById(R.id.getit2button);
display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenheight = size.y;
screenwidth = size.x;
Log.d(tag,"sssssssssssccreen size "+screenwidth);
if(screenwidth<1300)
cacmarg = screenwidth/50;
else
cacmarg = screenwidth/25;
init(layoutview);
return layoutview;
}


}





<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/getitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_alignParentLeft="true"
android:src="@drawable/backbutton"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:gravity="center"

android:orientation="horizontal">

<TextView

android:id="@+id/current_month"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/bluegrey"

android:textSize="28sp" />


<TextView

android:id="@+id/current_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="4dp"

android:textColor="@color/bluegrey"

android:textSize="28sp" />

</LinearLayout>

<ImageButton
android:id="@+id/getit2button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/forwardbutton"
/>
</RelativeLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:weightSum="7">


<Button

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/sunday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/monday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/tuesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/wednesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/thursday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/friday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/saturday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


</LinearLayout>


<LinearLayout

android:id="@+id/calendar_week_1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_4"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_5"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_6"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" /> </LinearLayout>

</ScrollView>

</LinearLayout>












share|improve this question

























  • Please edit your question to better describe the issue, and to include your code for Calview_frag, and the relevant layouts.

    – Mike M.
    Nov 26 '18 at 1:11











  • ok mike here is some more code hope it helps

    – Jason
    Nov 26 '18 at 14:43














0












0








0


0






I'm trying to implement Viewpager with a calendar. I'm using the same three instances of the calendar Fragment for testing the ViewPager lets call the smooth motion of transferring one fragment to the next SWIPING. the swiping will not work in the area of the fragment that the layout was created dynamically in the fragment itself but the rest of page(above and below the date buttons)the swiping works great! here is some of the code the entire frag code would not fit so had to edit some declarations and button listener methods



// Main Activity




public class calenderview extends AppCompatActivity {
ArrayList<Fragment> fraglist;
ViewPager pager;
calenderviewpageradaptor adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calenderview);
fraglist = new ArrayList<>();
fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag());
adaptor = new calenderviewpageradaptor(getSupportFragmentManager(),fraglist);
pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adaptor);
}



public class calenderviewpageradaptor extends FragmentStatePagerAdapter {

ArrayList<Fragment> adaptorlist;
public calenderviewpageradaptor(FragmentManager fm,ArrayList<Fragment> list){
super (fm);
this.adaptorlist = list;
}

@Override
public int getCount(){
return 3;
}
@Override
public Fragment getItem(int pos){
return adaptorlist.get(pos);

}
}


}




public class Calview_frag extends Fragment {




    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);



    }
private LinearLayout.LayoutParams getdaysLayoutParams() {
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

buttonParams.weight = 1;

return buttonParams;

}
private void addDaysinCalendar(ViewGroup.LayoutParams buttonParams, DisplayMetrics metrics) {

int engDaysArrayCounter = 0;

LinearLayout.LayoutParams doitwithmarg = new LinearLayout.LayoutParams(120,120);
doitwithmarg.setMarginStart(cacmarg);
LinearLayout.LayoutParams doittoit = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,


ViewGroup.LayoutParams.WRAP_CONTENT);
doittoit.weight=1;



        for (int weekNumber = 0; weekNumber < 6; ++weekNumber) {

for (int dayInWeek = 0; dayInWeek < 7; ++dayInWeek) {

Button day = new Button(getContext());

day.setBackground(getResources().getDrawable(R.drawable.roundshapeclear));
day.setTextColor(getResources().getColor(R.color.GREY));
day.setBackgroundColor(Color.TRANSPARENT);
day.setTextSize((int) metrics.density *5 );
day.setSingleLine();

if(dayInWeek!=0){
day.setLayoutParams(doitwithmarg);
Space s = new Space(getContext());
s.setLayoutParams(doittoit);
weeks[weekNumber].addView(s);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                  else{
day.setLayoutParams(doitwithmarg);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                ++engDaysArrayCounter;

}

}

}
private void init(View view) {

DisplayMetrics metrics = getResources().getDisplayMetrics();

calendar = Calendar.getInstance();



weekOneLayout = (LinearLayout)view.findViewById(R.id.calendar_week_1);

weekTwoLayout = (LinearLayout)view.findViewById(R.id.calendar_week_2);

weekThreeLayout = (LinearLayout)view.findViewById(R.id.calendar_week_3);

weekFourLayout = (LinearLayout)view.findViewById(R.id.calendar_week_4);

weekFiveLayout = (LinearLayout)view.findViewById(R.id.calendar_week_5);

weekSixLayout = (LinearLayout)view.findViewById(R.id.calendar_week_6);

currentYear = (TextView)view.findViewById(R.id.current_date);

currentMonth = (TextView)view.findViewById(R.id.current_month);

currentDateDay = chosenDateDay = calendar.get(Calendar.DAY_OF_MONTH);



if (userMonth != 0 && userYear != 0) {

currentDateMonth = chosenDateMonth = userMonth;

currentDateYear = chosenDateYear = userYear;

} else {

currentDateMonth = chosenDateMonth = calendar.get(Calendar.MONTH);

currentDateYear = chosenDateYear = calendar.get(Calendar.YEAR);

}



currentYear.setText("" + chosenDateYear);

currentMonth.setText(ENG_MONTH_NAMES[currentDateMonth]);


initializeDaysWeeks();

if (userButtonParams != null) {

defaultButtonParams = userButtonParams;

} else {

defaultButtonParams = getdaysLayoutParams();

}

addDaysinCalendar(defaultButtonParams,metrics);



initCalendarWithDate(chosenDateYear, chosenDateMonth, chosenDateDay,view);



}



private void initializeDaysWeeks() {

weeks = new LinearLayout[6];

days = new Button[6 * 7];

weeks[0] = weekOneLayout;

weeks[1] = weekTwoLayout;

weeks[2] = weekThreeLayout;

weeks[3] = weekFourLayout;

weeks[4] = weekFiveLayout;

weeks[5] = weekSixLayout;

}
private void initCalendarWithDate(int year, int month, int day, View v) {

if (calendar == null)

calendar = Calendar.getInstance();

calendar.set(year, month, day);

int daysInCurrentMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);


chosenDateYear = year;

chosenDateMonth = month;

chosenDateDay = day;

calendar.set(year, month, 1);

int firstDayOfCurrentMonth = calendar.get(Calendar.DAY_OF_WEEK);

Log.d(tag,"FFFFFFiiiiiiiiiiirrrrrrrrrrsssssssssst day of month int"+firstDayOfCurrentMonth);

calendar.set(year, month, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Log.d(tag,"LLLLLLLLLLLLlaaaaasttttttttttt day of month int"+daysInCurrentMonth);

int dayNumber = 1;

int daysLeftInFirstWeek = 0;
firstDayOfCurrentMonth= firstDayOfCurrentMonth-1;
int indexOfDayAfterLastDayOfMonth = 0;

if (firstDayOfCurrentMonth != 0) {

daysLeftInFirstWeek = firstDayOfCurrentMonth;

indexOfDayAfterLastDayOfMonth = daysLeftInFirstWeek + daysInCurrentMonth;

> for (int i = firstDayOfCurrentMonth; i < firstDayOfCurrentMonth + daysInCurrentMonth; ++i) {
//checks all dates of calendar to set background and text colors
if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay){
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}
>
for (int i = 7; i < 7 + daysInCurrentMonth; ++i) {

if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay) {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshape));


days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}

}


//Displays previous and next month days



        if (month > 0)

calendar.set(year, month - 1, 1);

else

calendar.set(year - 1, 11, 1);

int daysInPreviousMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);



for (int i = daysLeftInFirstWeek - 1; i >= 0; --i) {

int dateArr = new int[3];



if (chosenDateMonth > 0) {

if (currentDateMonth == chosenDateMonth - 1

&& currentDateYear == chosenDateYear

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = chosenDateMonth - 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 11

&& currentDateYear == chosenDateYear - 1

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));


}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = 11;

dateArr[2] = chosenDateYear - 1;

}

days[i].setTag(dateArr);
days[i].setTextColor(getResources().getColor(R.color.GREY));;

days[i].setText("");

days[i].setOnClickListener(null);

}

int nextMonthDaysCounter = 1;

for (int i = indexOfDayAfterLastDayOfMonth; i < days.length; ++i) {

int dateArr = new int[3];


if (chosenDateMonth < 11) {

if (currentDateMonth == chosenDateMonth + 1

&& currentDateYear == chosenDateYear

&& nextMonthDaysCounter == currentDateDay) {

// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = chosenDateMonth + 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 0

&& currentDateYear == chosenDateYear + 1

&& nextMonthDaysCounter == currentDateDay) {
// selectedDayButton.setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
selectedDayButton.setTextColor(Color.WHITE);
// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);
} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = 0;

dateArr[2] = chosenDateYear + 1;

}

days[i].setTag(dateArr);

days[i].setText("");
days[i].setOnClickListener(null);
}

calendar.set(chosenDateYear, chosenDateMonth, chosenDateDay);
currentYear.setText(" " + chosenDateYear);
currentMonth.setText(ENG_MONTH_NAMES[chosenDateMonth]);


}



public Calview_frag() {//required empty constructor
}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layoutview = inflater.inflate(R.layout.fragment_calview,container,false);
but = (ImageButton)layoutview.findViewById(R.id.getitbutton);
fbut = (ImageButton)layoutview.findViewById(R.id.getit2button);
display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenheight = size.y;
screenwidth = size.x;
Log.d(tag,"sssssssssssccreen size "+screenwidth);
if(screenwidth<1300)
cacmarg = screenwidth/50;
else
cacmarg = screenwidth/25;
init(layoutview);
return layoutview;
}


}





<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/getitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_alignParentLeft="true"
android:src="@drawable/backbutton"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:gravity="center"

android:orientation="horizontal">

<TextView

android:id="@+id/current_month"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/bluegrey"

android:textSize="28sp" />


<TextView

android:id="@+id/current_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="4dp"

android:textColor="@color/bluegrey"

android:textSize="28sp" />

</LinearLayout>

<ImageButton
android:id="@+id/getit2button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/forwardbutton"
/>
</RelativeLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:weightSum="7">


<Button

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/sunday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/monday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/tuesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/wednesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/thursday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/friday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/saturday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


</LinearLayout>


<LinearLayout

android:id="@+id/calendar_week_1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_4"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_5"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_6"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" /> </LinearLayout>

</ScrollView>

</LinearLayout>












share|improve this question
















I'm trying to implement Viewpager with a calendar. I'm using the same three instances of the calendar Fragment for testing the ViewPager lets call the smooth motion of transferring one fragment to the next SWIPING. the swiping will not work in the area of the fragment that the layout was created dynamically in the fragment itself but the rest of page(above and below the date buttons)the swiping works great! here is some of the code the entire frag code would not fit so had to edit some declarations and button listener methods



// Main Activity




public class calenderview extends AppCompatActivity {
ArrayList<Fragment> fraglist;
ViewPager pager;
calenderviewpageradaptor adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calenderview);
fraglist = new ArrayList<>();
fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag()); fraglist.add(new Calview_frag());
adaptor = new calenderviewpageradaptor(getSupportFragmentManager(),fraglist);
pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adaptor);
}



public class calenderviewpageradaptor extends FragmentStatePagerAdapter {

ArrayList<Fragment> adaptorlist;
public calenderviewpageradaptor(FragmentManager fm,ArrayList<Fragment> list){
super (fm);
this.adaptorlist = list;
}

@Override
public int getCount(){
return 3;
}
@Override
public Fragment getItem(int pos){
return adaptorlist.get(pos);

}
}


}




public class Calview_frag extends Fragment {




    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);



    }
private LinearLayout.LayoutParams getdaysLayoutParams() {
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

buttonParams.weight = 1;

return buttonParams;

}
private void addDaysinCalendar(ViewGroup.LayoutParams buttonParams, DisplayMetrics metrics) {

int engDaysArrayCounter = 0;

LinearLayout.LayoutParams doitwithmarg = new LinearLayout.LayoutParams(120,120);
doitwithmarg.setMarginStart(cacmarg);
LinearLayout.LayoutParams doittoit = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,


ViewGroup.LayoutParams.WRAP_CONTENT);
doittoit.weight=1;



        for (int weekNumber = 0; weekNumber < 6; ++weekNumber) {

for (int dayInWeek = 0; dayInWeek < 7; ++dayInWeek) {

Button day = new Button(getContext());

day.setBackground(getResources().getDrawable(R.drawable.roundshapeclear));
day.setTextColor(getResources().getColor(R.color.GREY));
day.setBackgroundColor(Color.TRANSPARENT);
day.setTextSize((int) metrics.density *5 );
day.setSingleLine();

if(dayInWeek!=0){
day.setLayoutParams(doitwithmarg);
Space s = new Space(getContext());
s.setLayoutParams(doittoit);
weeks[weekNumber].addView(s);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                  else{
day.setLayoutParams(doitwithmarg);
days[engDaysArrayCounter] = day;
weeks[weekNumber].addView(day);}



                ++engDaysArrayCounter;

}

}

}
private void init(View view) {

DisplayMetrics metrics = getResources().getDisplayMetrics();

calendar = Calendar.getInstance();



weekOneLayout = (LinearLayout)view.findViewById(R.id.calendar_week_1);

weekTwoLayout = (LinearLayout)view.findViewById(R.id.calendar_week_2);

weekThreeLayout = (LinearLayout)view.findViewById(R.id.calendar_week_3);

weekFourLayout = (LinearLayout)view.findViewById(R.id.calendar_week_4);

weekFiveLayout = (LinearLayout)view.findViewById(R.id.calendar_week_5);

weekSixLayout = (LinearLayout)view.findViewById(R.id.calendar_week_6);

currentYear = (TextView)view.findViewById(R.id.current_date);

currentMonth = (TextView)view.findViewById(R.id.current_month);

currentDateDay = chosenDateDay = calendar.get(Calendar.DAY_OF_MONTH);



if (userMonth != 0 && userYear != 0) {

currentDateMonth = chosenDateMonth = userMonth;

currentDateYear = chosenDateYear = userYear;

} else {

currentDateMonth = chosenDateMonth = calendar.get(Calendar.MONTH);

currentDateYear = chosenDateYear = calendar.get(Calendar.YEAR);

}



currentYear.setText("" + chosenDateYear);

currentMonth.setText(ENG_MONTH_NAMES[currentDateMonth]);


initializeDaysWeeks();

if (userButtonParams != null) {

defaultButtonParams = userButtonParams;

} else {

defaultButtonParams = getdaysLayoutParams();

}

addDaysinCalendar(defaultButtonParams,metrics);



initCalendarWithDate(chosenDateYear, chosenDateMonth, chosenDateDay,view);



}



private void initializeDaysWeeks() {

weeks = new LinearLayout[6];

days = new Button[6 * 7];

weeks[0] = weekOneLayout;

weeks[1] = weekTwoLayout;

weeks[2] = weekThreeLayout;

weeks[3] = weekFourLayout;

weeks[4] = weekFiveLayout;

weeks[5] = weekSixLayout;

}
private void initCalendarWithDate(int year, int month, int day, View v) {

if (calendar == null)

calendar = Calendar.getInstance();

calendar.set(year, month, day);

int daysInCurrentMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);


chosenDateYear = year;

chosenDateMonth = month;

chosenDateDay = day;

calendar.set(year, month, 1);

int firstDayOfCurrentMonth = calendar.get(Calendar.DAY_OF_WEEK);

Log.d(tag,"FFFFFFiiiiiiiiiiirrrrrrrrrrsssssssssst day of month int"+firstDayOfCurrentMonth);

calendar.set(year, month, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Log.d(tag,"LLLLLLLLLLLLlaaaaasttttttttttt day of month int"+daysInCurrentMonth);

int dayNumber = 1;

int daysLeftInFirstWeek = 0;
firstDayOfCurrentMonth= firstDayOfCurrentMonth-1;
int indexOfDayAfterLastDayOfMonth = 0;

if (firstDayOfCurrentMonth != 0) {

daysLeftInFirstWeek = firstDayOfCurrentMonth;

indexOfDayAfterLastDayOfMonth = daysLeftInFirstWeek + daysInCurrentMonth;

> for (int i = firstDayOfCurrentMonth; i < firstDayOfCurrentMonth + daysInCurrentMonth; ++i) {
//checks all dates of calendar to set background and text colors
if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay){
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}
>
for (int i = 7; i < 7 + daysInCurrentMonth; ++i) {

if (currentDateMonth == chosenDateMonth

&& currentDateYear == chosenDateYear

&& dayNumber == currentDateDay) {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshape));


days[i].setTextColor(Color.WHITE);

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

days[i].setTextColor(Color.BLACK);


}



int dateArr = new int[3];

dateArr[0] = dayNumber;

dateArr[1] = chosenDateMonth;

dateArr[2] = chosenDateYear;

days[i].setTag(dateArr);

days[i].setText(String.valueOf(dayNumber));



days[i].setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
onDayClick(v);

}

});

++dayNumber;

}

}


//Displays previous and next month days



        if (month > 0)

calendar.set(year, month - 1, 1);

else

calendar.set(year - 1, 11, 1);

int daysInPreviousMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);



for (int i = daysLeftInFirstWeek - 1; i >= 0; --i) {

int dateArr = new int[3];



if (chosenDateMonth > 0) {

if (currentDateMonth == chosenDateMonth - 1

&& currentDateYear == chosenDateYear

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = chosenDateMonth - 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 11

&& currentDateYear == chosenDateYear - 1

&& daysInPreviousMonth == currentDateDay) {

} else {
days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));


}



dateArr[0] = daysInPreviousMonth;

dateArr[1] = 11;

dateArr[2] = chosenDateYear - 1;

}

days[i].setTag(dateArr);
days[i].setTextColor(getResources().getColor(R.color.GREY));;

days[i].setText("");

days[i].setOnClickListener(null);

}

int nextMonthDaysCounter = 1;

for (int i = indexOfDayAfterLastDayOfMonth; i < days.length; ++i) {

int dateArr = new int[3];


if (chosenDateMonth < 11) {

if (currentDateMonth == chosenDateMonth + 1

&& currentDateYear == chosenDateYear

&& nextMonthDaysCounter == currentDateDay) {

// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);

} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = chosenDateMonth + 1;

dateArr[2] = chosenDateYear;

} else {

if (currentDateMonth == 0

&& currentDateYear == chosenDateYear + 1

&& nextMonthDaysCounter == currentDateDay) {
// selectedDayButton.setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
selectedDayButton.setTextColor(Color.WHITE);
// days[i].setBackground(getResources().getDrawable(R.drawable.roundshapegrey));
days[i].setTextColor(Color.WHITE);
} else {

days[i].setBackground(getResources().getDrawable(R.drawable.roundshapeclear));

}



dateArr[0] = nextMonthDaysCounter;

dateArr[1] = 0;

dateArr[2] = chosenDateYear + 1;

}

days[i].setTag(dateArr);

days[i].setText("");
days[i].setOnClickListener(null);
}

calendar.set(chosenDateYear, chosenDateMonth, chosenDateDay);
currentYear.setText(" " + chosenDateYear);
currentMonth.setText(ENG_MONTH_NAMES[chosenDateMonth]);


}



public Calview_frag() {//required empty constructor
}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layoutview = inflater.inflate(R.layout.fragment_calview,container,false);
but = (ImageButton)layoutview.findViewById(R.id.getitbutton);
fbut = (ImageButton)layoutview.findViewById(R.id.getit2button);
display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenheight = size.y;
screenwidth = size.x;
Log.d(tag,"sssssssssssccreen size "+screenwidth);
if(screenwidth<1300)
cacmarg = screenwidth/50;
else
cacmarg = screenwidth/25;
init(layoutview);
return layoutview;
}


}





<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/getitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_alignParentLeft="true"
android:src="@drawable/backbutton"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:gravity="center"

android:orientation="horizontal">

<TextView

android:id="@+id/current_month"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/bluegrey"

android:textSize="28sp" />


<TextView

android:id="@+id/current_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="4dp"

android:textColor="@color/bluegrey"

android:textSize="28sp" />

</LinearLayout>

<ImageButton
android:id="@+id/getit2button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/forwardbutton"
/>
</RelativeLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:weightSum="7">


<Button

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/sunday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/monday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/tuesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/wednesday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/thursday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/friday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


<Button

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@android:color/transparent"

android:text="@string/saturday"

android:textColor="@color/bluegrey"

android:textSize="16sp" />


</LinearLayout>


<LinearLayout

android:id="@+id/calendar_week_1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_4"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_5"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" />


<LinearLayout

android:id="@+id/calendar_week_6"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="7" /> </LinearLayout>

</ScrollView>

</LinearLayout>









android android-fragments android-viewpager






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 15:11







Jason

















asked Nov 26 '18 at 0:56









Jason Jason

13




13













  • Please edit your question to better describe the issue, and to include your code for Calview_frag, and the relevant layouts.

    – Mike M.
    Nov 26 '18 at 1:11











  • ok mike here is some more code hope it helps

    – Jason
    Nov 26 '18 at 14:43



















  • Please edit your question to better describe the issue, and to include your code for Calview_frag, and the relevant layouts.

    – Mike M.
    Nov 26 '18 at 1:11











  • ok mike here is some more code hope it helps

    – Jason
    Nov 26 '18 at 14:43

















Please edit your question to better describe the issue, and to include your code for Calview_frag, and the relevant layouts.

– Mike M.
Nov 26 '18 at 1:11





Please edit your question to better describe the issue, and to include your code for Calview_frag, and the relevant layouts.

– Mike M.
Nov 26 '18 at 1:11













ok mike here is some more code hope it helps

– Jason
Nov 26 '18 at 14:43





ok mike here is some more code hope it helps

– Jason
Nov 26 '18 at 14:43












1 Answer
1






active

oldest

votes


















0














are you passing the instance of the Fragment to the adapter? No I think. You should pass the list of fragments to the adapter along with fragment manager and should also change the calendarViewPager accordingly.



  List<Fragment> fragments =new ArrayList<>();
fragments.add(Calview_frag());
fragments.add(Calview_frag());
fragments.add(Calview_frag());
calenderviewpageradaptor adaptor =
new calenderviewpageradaptor(getSupportFragmentManager(),fragments);





share|improve this answer
























  • Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

    – Jason
    Nov 26 '18 at 14:42











  • Also tried getting rid of the scroll view with same results

    – Jason
    Nov 26 '18 at 18:39











  • I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

    – Jason
    Nov 26 '18 at 18:45











  • hey did you update the code in main activity? coz i didn't see that in the updated code

    – ABr
    Nov 27 '18 at 4:04











  • here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

    – Jason
    Nov 27 '18 at 15:14











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473543%2fviewpager-not-responding-to-touch-in-layout-area-created-dynamically-in-fragment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














are you passing the instance of the Fragment to the adapter? No I think. You should pass the list of fragments to the adapter along with fragment manager and should also change the calendarViewPager accordingly.



  List<Fragment> fragments =new ArrayList<>();
fragments.add(Calview_frag());
fragments.add(Calview_frag());
fragments.add(Calview_frag());
calenderviewpageradaptor adaptor =
new calenderviewpageradaptor(getSupportFragmentManager(),fragments);





share|improve this answer
























  • Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

    – Jason
    Nov 26 '18 at 14:42











  • Also tried getting rid of the scroll view with same results

    – Jason
    Nov 26 '18 at 18:39











  • I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

    – Jason
    Nov 26 '18 at 18:45











  • hey did you update the code in main activity? coz i didn't see that in the updated code

    – ABr
    Nov 27 '18 at 4:04











  • here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

    – Jason
    Nov 27 '18 at 15:14
















0














are you passing the instance of the Fragment to the adapter? No I think. You should pass the list of fragments to the adapter along with fragment manager and should also change the calendarViewPager accordingly.



  List<Fragment> fragments =new ArrayList<>();
fragments.add(Calview_frag());
fragments.add(Calview_frag());
fragments.add(Calview_frag());
calenderviewpageradaptor adaptor =
new calenderviewpageradaptor(getSupportFragmentManager(),fragments);





share|improve this answer
























  • Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

    – Jason
    Nov 26 '18 at 14:42











  • Also tried getting rid of the scroll view with same results

    – Jason
    Nov 26 '18 at 18:39











  • I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

    – Jason
    Nov 26 '18 at 18:45











  • hey did you update the code in main activity? coz i didn't see that in the updated code

    – ABr
    Nov 27 '18 at 4:04











  • here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

    – Jason
    Nov 27 '18 at 15:14














0












0








0







are you passing the instance of the Fragment to the adapter? No I think. You should pass the list of fragments to the adapter along with fragment manager and should also change the calendarViewPager accordingly.



  List<Fragment> fragments =new ArrayList<>();
fragments.add(Calview_frag());
fragments.add(Calview_frag());
fragments.add(Calview_frag());
calenderviewpageradaptor adaptor =
new calenderviewpageradaptor(getSupportFragmentManager(),fragments);





share|improve this answer













are you passing the instance of the Fragment to the adapter? No I think. You should pass the list of fragments to the adapter along with fragment manager and should also change the calendarViewPager accordingly.



  List<Fragment> fragments =new ArrayList<>();
fragments.add(Calview_frag());
fragments.add(Calview_frag());
fragments.add(Calview_frag());
calenderviewpageradaptor adaptor =
new calenderviewpageradaptor(getSupportFragmentManager(),fragments);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 5:32









ABrABr

28927




28927













  • Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

    – Jason
    Nov 26 '18 at 14:42











  • Also tried getting rid of the scroll view with same results

    – Jason
    Nov 26 '18 at 18:39











  • I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

    – Jason
    Nov 26 '18 at 18:45











  • hey did you update the code in main activity? coz i didn't see that in the updated code

    – ABr
    Nov 27 '18 at 4:04











  • here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

    – Jason
    Nov 27 '18 at 15:14



















  • Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

    – Jason
    Nov 26 '18 at 14:42











  • Also tried getting rid of the scroll view with same results

    – Jason
    Nov 26 '18 at 18:39











  • I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

    – Jason
    Nov 26 '18 at 18:45











  • hey did you update the code in main activity? coz i didn't see that in the updated code

    – ABr
    Nov 27 '18 at 4:04











  • here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

    – Jason
    Nov 27 '18 at 15:14

















Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

– Jason
Nov 26 '18 at 14:42





Thanks ABr I did try adding the above code in my Activity and modified the constructor it did not make a difference though I posted some more code hopefully that will help

– Jason
Nov 26 '18 at 14:42













Also tried getting rid of the scroll view with same results

– Jason
Nov 26 '18 at 18:39





Also tried getting rid of the scroll view with same results

– Jason
Nov 26 '18 at 18:39













I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

– Jason
Nov 26 '18 at 18:45





I was wondering if I needed some kind of callback in the fragment after it created its views to the viewpager

– Jason
Nov 26 '18 at 18:45













hey did you update the code in main activity? coz i didn't see that in the updated code

– ABr
Nov 27 '18 at 4:04





hey did you update the code in main activity? coz i didn't see that in the updated code

– ABr
Nov 27 '18 at 4:04













here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

– Jason
Nov 27 '18 at 15:14





here is my updated activity code that did not change the problem. I did not see much on passing a list to the adaptor so I could be way off here

– Jason
Nov 27 '18 at 15:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473543%2fviewpager-not-responding-to-touch-in-layout-area-created-dynamically-in-fragment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks