Use the scroll of a Listview to select each component by means of a TextToSpeech

0

Good day, I need to use the scroll of a ListView that as it moves indicates what is in each position of the vector by means of a TextToSpeech, until now it works for me if I press each vector, it tells me what is there in that position, but now I need that as I move the scroll I indicate the position without the need to select it, I have consulted the methods of the scrollView but it does not work for me.

This is the code I have at this time.

private ListView lv1 ;
private TextView tv11;
private TextToSpeech tts;

private int index; //  creamos un interger llamado índex que será útil para determinar la posición de nuestro artículo.


// creamos una matriz llamada nombres que contiene nuestros elementos de lista estáticos
private String nombres [] = {"Edificio A", "Edificio B", "Edificio C", "Edificio E","Edificio P","Restaurante", "Biblioteca","Casita de Biología","Salón Multi-Propósito", "Baños","Enfermería"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_modulo_ciegos); // básicamente configuramos la vista de esta actividad en nuestro diseño xml llamado activity main

    tts = new TextToSpeech(this,this); // comunica la parte lógica con la gráfica
    lv1=(ListView)findViewById(R.id.listview);  // ahora llamamos a nuestro elemento listview llamado lv1
    lv1.getMaxScrollAmount();


    ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.listview_item_interfaz1, nombres); //Asignar el vector
    lv1.setAdapter(adapter); // Estamos mapeando lv1 (vista de lista) a nuestro adaptador de matriz
    lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            index= i;

            // tv11.setText(nombres[i]);
            Toast.makeText(getApplicationContext(), nombres[index], Toast.LENGTH_SHORT).show();
            tts.speak(nombres[index], TextToSpeech.QUEUE_ADD, null);







        }
    });




}


public void onInit(int status) {
    // TODO Auto-generated method stub
    //verificamos si se proporciona texto a voz en el dispositivo
    if (status == TextToSpeech.SUCCESS)
    {

        Toast.makeText( this, "Text-To-Speech SYNTHESIS engine is ready" , (Toast.LENGTH_SHORT));

    }

    //  Si no se admite texto a voz, emitimos un mensaje de error
    else if (status== TextToSpeech.ERROR)
    {
        Toast.makeText(this,"Error occurred while initializing Text-To-Speech engine probably you dont have it installed", Toast.LENGTH_LONG).show();
    }

}

}

    
asked by Byron 01.05.2018 в 19:41
source

0 answers