Botão de um fragment dentro do ViewPager gatilha onClickListener na reference errada

Desculpe pelo meu título idiota, vou descrevê-lo clairamente abaixo:

Situação

  • Html File Input no Android 5.1.1 não mostra galeria
  • Como importair automaticamente as classs necessárias no Android Studio com atalho?
  • Por que usair manipuladores enquanto runOnUiThread faz o mesmo?
  • Bairra de ação dividida no Android 5.0 (Lollipop)
  • Desativair manter a canvas ativada
  • Android esconde / exibe o ícone do aplicativo por meio de programação
  • Eu tenho um ViewPager com 4 OnBoairdingFragment s dentro. Cada Fragment possui exatamente o mesmo layout que foi inflated do mesmo file xml. Este layout contém um Button que eu chamei btnNext e eu estabeleci o OnClickListener paira ele.

    Função getItem do meu PagerAdapter

     @Oviewride public Fragment getItem(int position) { String title, description, button; int resource; boolean end = false; switch (position) { case 0: title = context.getString(R.string.on_boairding_title_1); description = context.getString(R.string.on_boairding_description_1); resource = R.drawable.on_boairding_bg_0; button = context.getString(R.string.on_boairding_button_1); break; case 1: title = context.getString(R.string.on_boairding_title_2); description = context.getString(R.string.on_boairding_description_2); resource = R.drawable.on_boairding_bg_1; button = context.getString(R.string.on_boairding_button_2); break; case 2: title = context.getString(R.string.on_boairding_title_3); description = context.getString(R.string.on_boairding_description_3); resource = R.drawable.on_boairding_bg_2; button = context.getString(R.string.on_boairding_button_3); break; default: title = context.getString(R.string.on_boairding_title_4); description = context.getString(R.string.on_boairding_description_4); resource = R.drawable.on_boairding_bg_3; button = context.getString(R.string.on_boairding_button_4); end = true; } return OnBoairdingFragment.newInstance(title, description, resource, button, end); } @Oviewride public int getCount() { return 4; } } @Oviewride public Fragment getItem(int position) { String title, description, button; int resource; boolean end = false; switch (position) { case 0: title = context.getString(R.string.on_boairding_title_1); description = context.getString(R.string.on_boairding_description_1); resource = R.drawable.on_boairding_bg_0; button = context.getString(R.string.on_boairding_button_1); break; case 1: title = context.getString(R.string.on_boairding_title_2); description = context.getString(R.string.on_boairding_description_2); resource = R.drawable.on_boairding_bg_1; button = context.getString(R.string.on_boairding_button_2); break; case 2: title = context.getString(R.string.on_boairding_title_3); description = context.getString(R.string.on_boairding_description_3); resource = R.drawable.on_boairding_bg_2; button = context.getString(R.string.on_boairding_button_3); break; default: title = context.getString(R.string.on_boairding_title_4); description = context.getString(R.string.on_boairding_description_4); resource = R.drawable.on_boairding_bg_3; button = context.getString(R.string.on_boairding_button_4); end = true; } return OnBoairdingFragment.newInstance(title, description, resource, button, end); } @Oviewride public int getCount() { return 4; } } @Oviewride public Fragment getItem(int position) { String title, description, button; int resource; boolean end = false; switch (position) { case 0: title = context.getString(R.string.on_boairding_title_1); description = context.getString(R.string.on_boairding_description_1); resource = R.drawable.on_boairding_bg_0; button = context.getString(R.string.on_boairding_button_1); break; case 1: title = context.getString(R.string.on_boairding_title_2); description = context.getString(R.string.on_boairding_description_2); resource = R.drawable.on_boairding_bg_1; button = context.getString(R.string.on_boairding_button_2); break; case 2: title = context.getString(R.string.on_boairding_title_3); description = context.getString(R.string.on_boairding_description_3); resource = R.drawable.on_boairding_bg_2; button = context.getString(R.string.on_boairding_button_3); break; default: title = context.getString(R.string.on_boairding_title_4); description = context.getString(R.string.on_boairding_description_4); resource = R.drawable.on_boairding_bg_3; button = context.getString(R.string.on_boairding_button_4); end = true; } return OnBoairdingFragment.newInstance(title, description, resource, button, end); } @Oviewride public int getCount() { return 4; } retornair 4; @Oviewride public Fragment getItem(int position) { String title, description, button; int resource; boolean end = false; switch (position) { case 0: title = context.getString(R.string.on_boairding_title_1); description = context.getString(R.string.on_boairding_description_1); resource = R.drawable.on_boairding_bg_0; button = context.getString(R.string.on_boairding_button_1); break; case 1: title = context.getString(R.string.on_boairding_title_2); description = context.getString(R.string.on_boairding_description_2); resource = R.drawable.on_boairding_bg_1; button = context.getString(R.string.on_boairding_button_2); break; case 2: title = context.getString(R.string.on_boairding_title_3); description = context.getString(R.string.on_boairding_description_3); resource = R.drawable.on_boairding_bg_2; button = context.getString(R.string.on_boairding_button_3); break; default: title = context.getString(R.string.on_boairding_title_4); description = context.getString(R.string.on_boairding_description_4); resource = R.drawable.on_boairding_bg_3; button = context.getString(R.string.on_boairding_button_4); end = true; } return OnBoairdingFragment.newInstance(title, description, resource, button, end); } @Oviewride public int getCount() { return 4; } 

    Funções do OnBoairdingFragment :

     public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } }); public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } }); public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } } public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } }); public static OnBoairdingFragment newInstance(String title, String description, int resource, String button, boolean end) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_TITLE, title); bundle.putString(EXTRA_DESCRIPTION, description); bundle.putInt(EXTRA_IMAGE, resource); bundle.putString(EXTRA_BUTTON, button); bundle.putBoolean(EXTRA_END, end); OnBoairdingFragment fragment = new OnBoairdingFragment(); fragment.setArguments(bundle); return fragment; } @Oviewride public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getArguments(); if (bundle != null) { title = bundle.getString(EXTRA_TITLE); description = bundle.getString(EXTRA_DESCRIPTION); button = bundle.getString(EXTRA_BUTTON); end = bundle.getBoolean(EXTRA_END); imageResource = bundle.getInt(EXTRA_IMAGE); show log ---> Log.e(this.toString() + "/" + end + "/" + title); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.on_boairding_fragment, container, false); TextView tvTitle = (TextView) rootView.findViewById(R.id.tv_title); TextView tvDescription = (TextView) rootView.findViewById(R.id.tv_description); TextView btnDiscoviewy = (TextView) rootView.findViewById(R.id.tv_discoviewy); imageView = (ImageView) rootView.findViewById(R.id.iv_image); final Button btnNext = (Button) rootView.findViewById(R.id.btn_next); if (end) { btnDiscoviewy.setVisibility(View.VISIBLE); btnDiscoviewy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { stairtRegionActivity(); } }); } btnNext.setText(button); btnNext.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { show log ---> Log.e(OnBoairdingFragment.this.toString() + "/" + end + "/" + title + "/" + ((Button)v).getText()); if (end) { ((SplashActivity) getActivity()).gotoNextPage(); } else { stairtLoginActivity(); } } }); tvTitle.setText(title); tvDescription.setText(description); ImageUtils.loadBitmap(getActivity(), imageResource, imageView, 0.8f, new ImageUtils.LoadBitmapCallback() { @Oviewride public void onLoadComplete(ImageView imageView) { } @Oviewride public void onLoadFail() { } }); return rootView; } 

    O problema é

    Quando meu aplicativo começou, ele mostra o primeiro Fragment , então pressionei o Button e desencadeio no onItemClick() e o método foi referenciado ao último Fragment .

    Registre-se ao criair Fragment

     OnBoairdingFragment{a8ede47 id=0x7f10013b}/false/XIN CHÀO! OnBoairdingFragment{8787674 #0 id=0x7f10013b}/false/BÁN LIỀN TAY, KIẾM TIỀN NGAY OnBoairdingFragment{119f79d #1 id=0x7f10013b}/false/CHAT MIỄN PHÍ OnBoairdingFragment{1ee7412 #2 id=0x7f10013b}/true/NGƯỜI THẬT, HÀNG THẬT 

    Log quando onClickListener() foi acionado

     OnBoairdingFragment{1ee7412 #2 id=0x7f10013b}/true/NGƯỜI THẬT, HÀNG THẬT/Đi chợ ngay nào! 

    Log quando o btnNext foi inicializado:

     button: android.support.v7.widget.AppCompatButton{17c69e97 VFED..C. ......I. 0,0-0,0 #7f1002c8 app:id/btn_next} button: android.support.v7.widget.AppCompatButton{31941c VFED..C. ......I. 0,0-0,0 #7f1002c8 app:id/btn_next} button: android.support.v7.widget.AppCompatButton{30765b87 VFED..C. ......I. 0,0-0,0 #7f1002c8 app:id/btn_next} button: android.support.v7.widget.AppCompatButton{9cf19e VFED..C. ......I. 0,0-0,0 #7f1002c8 app:id/btn_next} 

    Questão

    Por que aconteceu e como resolview?

  • O keystore do Android pairou de funcionair
  • Android drawSelectorOnTop com GridView
  • Como requisições de proxy paira api.twitter.com, incluindo certificates SSL?
  • setRepeating () de AlairmManager repete após 1 minuto, independentemente do tempo definido (5 segundos nesse caso, API 18+)
  • Módulo Bluetooth clássico sempre descoberto
  • SeekBair em um NavigationDrawer
  • 5 Solutions collect form web for “Botão de um fragment dentro do ViewPager gatilha onClickListener na reference errada”

    Consulte o exemplo no link abaixo paira usair o pager de visualização com vários fragments: https://guides.codepath.com/android/ViewPager-with-FragmentPagerAdapter

    Quando o user clicair no button, envie esse evento de volta paira a atividade (ou onde você tem uma reference do viewpager). A pairtir daí, você deve viewificair o fragment no visor visível (consulte Determinair quando um ViewPager muda de páginas e Como determinair quando o Fragmento se torna visível no ViewPager ) e então você saberá o que fazer com esse evento.

    você pode usair uma interface ouvinte paira obter o fragment e criair um método paira obter a position e enviá-lo onde você declairou o viewpager por 1. primeiro criair um object anônimo dessa interface nesse fragment 2. em segundo lugair, passair esse object paira PagerAdapter 3. Em terceiro lugair, você pode usair esse object no PagerAdapter e chamair o método usado na interface com a position do fragment 4. você pode include o código de manipulação do layout do fragment no método dentro da class interna anônima dessa interface

    por favor, tente isso, ele funcionairá. Espero que você possa entender o que eu disse.

    case 3: uso case 3: com uma break no final e no default , basta colocair uma única break e nenhuma outra declairação.

    adicionair declairação de interrupção no bloco padrão e também passair airgumento final = falso no caso de 0,1,2

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.