0

estoy desarrollando una app con ViewPagers y swipe y resulta que tengo estos errores que no sé cómo se resuelven.

error: saludos is not abstract and does not override abstract method onFragmentInteraction(Uri) in OnFragmentInteractionListener

error: method does not override or implement a method from a supertype

He leído que esto se resolvía con la siguiente función
@Override public void OnFragmentInteraction(Uri uri) {

}

pero sigo teniendo un error,

package activities;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import com.flixarts.ar.*.R;
import com.flixarts.ar.*.fragment1;
import com.flixarts.ar.*.fragment2;
import com.flixarts.ar.*.fragment3;
import com.flixarts.ar.*.fragment4;
import com.flixarts.ar.*.menuscreen;

public class saludos extends FragmentActivity implements fragment1.OnFragmentInteractionListener, fragment2.OnFragmentInteractionListener, fragment3.OnFragmentInteractionListener, fragment4.OnFragmentInteractionListener {

private TextView espacioFrases;
private TextView espacioFrasesTraducidas;
private Button next;
private Button buttonHome;
private ViewPager mPager;
private PagerAdapter pagerAdapter;
private static final int NUM_PAGES = 4;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_saludos);
 mPager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
    mPager.setAdapter(pagerAdapter);



}
@Override
public void onBackPressed(){
    if (mPager.getCurrentItem() == 0) {
        super.onBackPressed();
    }
    else {
             mPager.setCurrentItem(mPager.getCurrentItem() -1);
    }
}

@Override
public void OnFragmentInteraction(Uri uri) {

}

private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
    public ScreenSlidePagerAdapter(FragmentManager fm){
        super(fm);
    }
    @Override
    public Fragment getItem(int position){
        switch (position){
            case 0: return new fragment1();
            case 1: return new fragment2();
            case 2: return new fragment3();
            case 3: return new fragment4();
            default: return new fragment1();
        }
    }

    @Override
    public int getCount(){
        return NUM_PAGES;
    }

}

String[] frases = {"Hello!", "Hi!", "How are you?", "Good and you?", "I'm fine", "I'm ok", "How do you do?", "How've you been?", "Good Morning", "Good Afternoon", "Good Evening", "Good Nights", "What's new?", "What's up?", "What Happens!"};
String[] frasesTraducidas = {"Hola!", "Hola!", "¿Cómo estás?", "Bien y tú?", "Estoy bien", "Estoy bien", "¡Cómo te va!", "Cómo has estado?", "Buenos días", "Buenas tardes", "Buenas noches", "Buenas noches", "¿Qué hay de nuevo?", "¡Qué pasa!"};



int frasesindice = 0;
int frasestraducidasindice = 0;


String fraseamostrar = "";






public void openHome() {
    Intent intent = new Intent(this, menuscreen.class);
    startActivity(intent);
}

public void abrirCongratulations() {
    Intent intent = new Intent(this, congratulations.class);
    startActivity(intent);
    String activityName = this.getClass().getSimpleName();
}
}
2
  • Buenas! Viendo que ya tienes 5 preguntas y no has aceptado ninguna respuesta, te invito a repasar el recorrido de bienvenida para que veas como funciona este sitio.
    – SJuan76
    el 17 jun. 2019 a las 23:10
  • Gracias! no sabía muy bien como funcionaba ese botón.. saludos el 18 jun. 2019 a las 0:02

2 respuestas 2

1
@Override
public void OnFragmentInteraction(Uri uri) {

}

En primer lugar, traducir override por "anular" es incorrecto. @Override indica que el método marcado esta implementando/sobreescribiendo un método de la clase padre o de una de las interfaces implementadas; si marcas un método con @Override entonces o la clase padre o una de las interfaces tiene que tener definido un método void OnFragmentInteraction(Uri).

Te da el error porque la clase padre tiene un método void onFragmentInteraction(Uri), no un método void OnFragmentInteraction(Uri uri) (fíjate que la primera "O" está en mayúscula en tu método1, no tienen el mismo nombre así que no son el mismo método).

Eso también te causa el segundo error; por implementar fragment1.OnFragmentInteractionListener debes implementar un método onFragmentInteraction(URI), pero como ya hemos dicho OnFragmentInteraction(URI) no sirve porque el nombre es diferente.

*1 Si te familiarizas con el sistema de nomenclatura de Java (nombres de métodos en camelCase siempre) te será mucho más sencillo detectar estos errores.

0

Tu clase saludos debe implementar el método onFragmentInteraction. Te lo ha dicho muy claro. Tu clase implementa fragment1.OnFragmentInteractionListener y este listener, que es interface, tiene el método onFragmentInteraction. Implementa dicho método en tu clase.

1
  • El que ha votado en negativo que explique por qué. Qué es lo que no le gusta el 19 jun. 2019 a las 5:46

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.