Element of the Android List

Asked

Viewed 109 times

2

I have a list of sounds, wanted to take each element of the list and emit the sound that is recorded in the bank. Example: when clicking on an element that is in the list, emitted the recorded sound that is in the database, I already have everything recorded, just wanted to know how I do to when clicking send the sound.

public static final String KEY_SOM = "NomeSom";

String Som = "CREATE TABLE IF NOT EXISTS tabSom3 ( `_id` INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                "`NomeSom`	TEXT, " +
                "`ArqSom`	TEXT);";  

public void CarregaDadoSom(){
    MostraDados = (ListView) findViewById(R.id.lstSom);

    if(VerificaRegistroSom()){
        String [] Coluna = new String [] {KEY_SOM};;

        AdapterLista = new SimpleCursorAdapter(this, R.layout.lista_som, cursor, Coluna, new int[] {R.id.txtsom});

        MostraDados.setAdapter(AdapterLista);
    }else {
        MensagemAlerta("Erro Banco de Dados", "Você não possui nenhum cadastro!");
    }
   
}

private boolean VerificaRegistroSom() {
    try {
        BancoDados = openOrCreateDatabase(NomeBanco, MODE_WORLD_READABLE, null);
        cursor = BancoDados.rawQuery("Select * from tabSom3", null);

        if (cursor.getCount() != 0) { //procurar registro no banco
            cursor.moveToFirst();
            return true;
        } else{
            return false;
        }
    } catch(Exception erro){
        MensagemAlerta("Erro Banco de Dados", "Não foi possivel VERIFICAR dados " + erro);
        return false;
    } finally {
        BancoDados.close();
    }
}

public void play(View view) {
    try{
        myPlayer = new MediaPlayer();
        myPlayer.setDataSource(outputFile);
        myPlayer.prepare();
        myPlayer.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void stopPlay(View view){
    try {
        if (myPlayer != null) {
            myPlayer.stop();
            myPlayer.release();
            myPlayer = null;

        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

`.xml`:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text=""
        android:id="@+id/txtsom"
        android:layout_gravity="center_horizontal"
        android:textSize="30dp" />

</LinearLayout>

Only in my list appears the name of the sound, but I wanted it to emit the recorded sound.

  • What kind of given sound is being recorded at the bank?

  • I edited the code, it takes the path of sound

  • What is the content of KEY_SOM?

  • edited in the code

1 answer

1

Show 1 more comment

Browser other questions tagged

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