How to send a query to an arrayadapter?

0

I'm trying to pass a query from an sqlite to an arrayadapter that will consume the query as a string, but I'm not getting the arrayadapter to populate my view.

follow view code:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".DisplayProdutos"
    tools:showIn="@layout/activity_display_produtos">


    <SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:hint="@string/hint_busca"
        />

    <Button
        android:id="@+id/button5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="59dp"
        android:layout_marginRight="10dp"
        android:background="@color/btColor"
        android:text="@string/bt_buscas"
        android:textColor="@color/btTextColor"
        android:textFontWeight="bolder" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button5"
        android:layout_alignParentTop="true"
        android:layout_marginTop="121dp"
        android:text="TextView" />

    <ListView
        android:id="@+id/listaView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignStart="@+id/button5"
        android:layout_alignParentTop="true"
        android:layout_marginTop="148dp" />


</RelativeLayout>

follows java class:

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class DisplayProdutos extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_produtos);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        //torna o banco de dados universal dentro da classe
        DB_HELPER appBD;

        //instância a recycler view
        //RecyclerView Lista_R = (RecyclerView)findViewById(R.id.lista);

        //instancia do list view
        ListView lv_front = (ListView)findViewById(R.id.listaView);

        //instância o botão fab
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        //comprime o metodo de impressão de dados em uma string
        String impressao = "appBD.imprime();";

        //torna a string anterior em um array
        String[] produtos = {impressao};

        ArrayAdapter<String> adaptador;


        //popula a list view

        adaptador = new ArrayAdapter<String>(this, R.layout.content_display_produtos, R.id.listaView);
        lv_front.setAdapter(adaptador);






        //evento que chama a tela de input de dados
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                //encaminha a página de cadastro de produtos

                Snackbar.make(view, null, Snackbar.LENGTH_LONG)
                        .setAction( "Prosseguir", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent passaPageCadastro = new Intent(DisplayProdutos.this , CadastrarProdutoActivity.class);
                                startActivity(passaPageCadastro);
                            }
                        }).show();
            }
        });




    }

}

follows sqlite database method for query:

 public Cursor imprime()
    {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery("SELECT "
        + DB_NAME_TABLE_PRODUTOS
        + " FROM "
        + DB_TABLE_PRODUTOS
        + " WHERE  "
        + DB_ID_TABLE_PRODUTOS
        + " = ?",

                new String[1]
        );
        return cursor;
    }

This is generated log:

11-08 21:08:49.693 1611-1771/system_process A/ProcessStats: ProcessState dead: name=com.android.systemui pkg=com.android.keyguard uid=10007 common.name=com.android.systemui
    android.util.Log$TerribleFailure: ProcessState dead: name=com.android.systemui pkg=com.android.keyguard uid=10007 common.name=com.android.systemui
        at android.util.Log.wtf(Log.java:290)
        at android.util.Slog.wtfStack(Slog.java:86)
        at com.android.internal.app.ProcessStats$ProcessState.ensureNotDead(ProcessStats.java:2495)
        at com.android.internal.app.ProcessStats$ProcessState.setState(ProcessStats.java:2593)
        at com.android.internal.app.ProcessStats$ProcessState.setState(ProcessStats.java:2578)
        at com.android.server.am.ActivityManagerService.setProcessTrackerState(ActivityManagerService.java:15348)
        at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:15631)
        at com.android.server.am.ActivityManagerService.appDiedLocked(ActivityManagerService.java:3754)
        at com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied(ActivityManagerService.java:1026)
        at android.os.BinderProxy.sendDeathNotice(Binder.java:493)
        at dalvik.system.NativeStart.run(Native Method)
    
asked by anonymous 08.11.2018 / 14:56

0 answers