Listview getting blob image and sqlite name

0

I'm trying to populate a listview with names and phones, images and ids (id will not be shown, served only when I click on the desired clients, play to another activity requesting the information found through the id), I tried to increment my code with other posts related to my question, but without success, can anyone help me? I'm not a programmer, I'm just trying to learn more as a hobby, what I have so far ...

Datasource.java searching in db for information

    public List<String> getAllClients(){
    List<String> list = new ArrayList<String>();

    String selectQuery = "SELECT * FROM userDB ORDER BY nome ASC";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
            list.add(cursor.getString(2));
        } while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return list;
}

MainActivity.java that has the adapter

private void ClientList() {

    DataSource db = new DataSource(getApplicationContext());
    List<String> clientlist = db.getAllClients();
    clientAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, clientlist);
    clientList.setAdapter(clientAdapter);

}

content_main.xml containing a searchview and the listview

<SearchView
    android:id="@+id/searchView"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="5dp"
    android:queryHint="@string/search"
    android:iconifiedByDefault="false"
    android:background="#FFFFFF"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ListView
    android:id="@+id/listview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/searchView" />

I've found that for what I want I have to have a custom listview, so it would be this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="5dp"
    android:layout_marginTop="5dp"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/perfil_image_cliente"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginEnd="20dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="20dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="5dp"
        android:src="@drawable/perfil_image" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/nome_lista_client"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="20dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="20dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="5dp"
            android:text="Nome: "
            android:textColor="#008080"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/fone_lista_client"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="20dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="20dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="5dp"
            android:text="Fone: "
            android:textColor="@color/common_google_signin_btn_text_dark_focused"
            android:textSize="18sp" />

    </LinearLayout>
</LinearLayout>

    
asked by anonymous 18.07.2018 / 22:42

0 answers