Android - Delete text in a ListView

1

I created a task application to be made that is displayed in a ListView.

I'm using SQLite with a table with the columns: ID, task, completed.

I want you to scroll through the records, if the "completed" column is equal to "s", the text in the ListView will appear with a scratch in the middle of it. Is there any way to do this?

This code is in the recovery method Tasks () that searches all jobs registered in the SQLite database:

//Recuperar as tarefas
        Cursor cursor = bancoDeDados.rawQuery("SELECT * FROM tarefas ORDER BY id DESC", null);

        //recuperar ids das colunas
        int indiceColunaId = cursor.getColumnIndex("id");
        int indiceColunaTarefa = cursor.getColumnIndex("tarefa");
        int indiceColunaConcluida = cursor.getColumnIndex("concluida");


        //cria o adaptador
        itens = new ArrayList<String>();
        itensAdaptador = new ArrayAdapter<String>(getApplicationContext(),
                R.layout.items_list,
                android.R.id.text1,
                itens);

        idsTarefas = new ArrayList<Integer>();
        listaTarefas.setAdapter(itensAdaptador);

        //Lista as tarefas - quando usa o rawquery ele fica parado no ultimo registro
        cursor.moveToFirst();
        while (cursor != null){

            if (cursor.getString(indiceColunaConcluida) == "s"){

                itens.add(cursor.getString(indiceColunaTarefa));
                //Aqui quero colocar que o texto fica riscado

            } else {
                itens.add(cursor.getString( indiceColunaTarefa ));
                //Aqui o texto deve ficar normal (sem risco)
            }

            idsTarefas.add( Integer.parseInt( cursor.getString(indiceColunaId) ) );
            cursor.moveToNext();

        }
    
asked by anonymous 01.06.2018 / 13:54

2 answers

2

What I did to scratch the text in the ListView was as follows:

Instead of creating ArrayList of type String I changed to SpannableArrayList:

private ArrayAdapter<SpannableString> itensAdaptador;
private ArrayList<SpannableString> itens;

And I used the SpannableString class to create a scratched text as follows:

 SpannableString textoRiscado = new SpannableString(cursor.getString(indiceColunaTarefa));
 textoRiscado.setSpan(new StrikethroughSpan(), 0, textoRiscado.length(), 0 );

And then simply added the Text object to the list of items.

itens.add(textoRiscado);

It worked perfectly

    
03.06.2018 / 06:18
5

I hope this helps.

TextView tv = (TextView) findViewById(R.id.mytext);
    tv.setText("Texto com risco");
    tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    
01.06.2018 / 15:06