Imageviewpageadapter cannot be Applied error

Asked

Viewed 32 times

1

Can anyone help me with this error? It occurs when executing a setarView method. Follow the code:

package ufc.es.com.br.doesempre.modelo;

import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;


import ufc.es.com.br.doesempre.R;

/**
 * Created by 349059 on 16/06/16.
 */
public class Fragmento_Principal extends Fragment {
    private ViewPager viewPager;
    private ImageViewPagerAdapter imPadpter;
    private ImageView bt1, bt2, bt3;

    public Fragmento_Principal() {
    }

    @Override
    public void onViewCreated(View v, Bundle bd) {
        super.onViewCreated(v, bd);
        setarView();
        setarTab();
        clicBotaoCirculado();
    }

        public View onCreatedView(LayoutInflater infl, ViewGroup cont, Bundle savedInstanceState) {
        return infl.inflate(R.layout.fragmento_principal, cont, false);
    }

    private void clicBotaoCirculado() {
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bt1.setImageResource(R.drawable.circulo_cheio);
                viewPager.setCurrentItem(0);

            }
        });

        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bt1.setImageResource(R.drawable.circulo_cheio);
                viewPager.setCurrentItem(1);
            }
        });

        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bt1.setImageResource(R.drawable.circulo_cheio);
                viewPager.setCurrentItem(2);
            }
        });
    }

    private void setarView() {
        viewPager = (ViewPager) viewPager.findViewById(R.id.viewImageFragMain);
        imPadpter = new ImageViewPagerAdapter(getActivity(),getFragmentManager());
        viewPager.setAdapter(imPadpter);
        viewPager.setCurrentItem(0);
        iniciarBotao();
    }

    private void setarTab() {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrollStateChanged(int posicao) {
            }

            public void onPageScrolled(int a, float b, int c) {
            }

            @Override
            public void onPageSelected(int posicao) {
                bt1.setImageResource(R.drawable.circulo);
                bt2.setImageResource(R.drawable.circulo);
                bt3.setImageResource(R.drawable.circulo);
                acaoDoBotao();
            }
        });
    }

    private void acaoDoBotao(int acao) {
        switch (acao) {
            case 1:
                bt1.setImageResource(R.drawable.circulo_cheio);
                break;
            case 2:
                bt2.setImageResource(R.drawable.circulo_cheio);
                break;
            case 3:
                bt3.setImageResource(R.drawable.circulo_cheio);
                break;
        }
    }

    private void iniciarBotao() {
        bt1 = (ImageView) getView().findViewById(R.id.btn1);
        bt1.setImageResource(R.drawable.circulo_cheio);
        bt2 = (ImageView) getView().findViewById(R.id.btn2);
        bt3 = (ImageView) getView().findViewById(R.id.btn3);
    }

    private void setarBotao(Button btn, String txt, int altura, int largura){
        btn.setHeight(altura);
        btn.setWidth(largura);
        btn.setText(txt);
    }

}

Returns the following error:

(in Imageviewpageadapter cannot be Applied to (Activity android.app.Fragmentmanager)

1 answer

0

Fala Rico,

Probably the problem is in your Viewpager statement.

Do the following, declare a View:

private View rootView;

Now, change your own:

public View onCreatedView(LayoutInflater infl, ViewGroup cont, Bundle savedInstanceState) {
     return infl.inflate(R.layout.fragmento_principal, cont, false);
}

for

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

     rootView = inflater.inflate(R.layout.fragmento_principal, container, false);

     return rootView;
}

Now, when declaring the view pager, change this:

viewPager = (ViewPager) viewPager.findViewById(R.id.viewImageFragMain);

That’s why:

viewPager = (ViewPager) rootView.findViewById(R.id.viewImageFragMain);

Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.