I am currently working on a task app. I have saved data like task name, time and priority from the user into the room. Now, I created a custom adapter and a custom list view. Now I want to connect the data from the room so that I can put it into the custom list view. How can I do that? This is the code for the adapter class :
<pre>package com.example.taskmasterv3;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.room.Insert;
import java.util.ArrayList;
public class SummaryListAdapter extends ArrayAdapter<SummaryList> {
private final Context context;
private ArrayList<SummaryList> values;
public SummaryListAdapter(Context context, ArrayList<SummaryList> list) {
super(context, 0, list);
this.context = context;
this.values = list;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.task_summary_item, parent, false);
}
TextView tvloltaskname = convertView.findViewById(R.id.tvloltaskname);
ImageView ivlolPri = convertView.findViewById(R.id.ivlolPri);
ImageView ivlolTime = convertView.findViewById(R.id.ivlolTime);
AppDatabase.databaseWriteExecutor.execute(new Runnable() {
@Override
public void run() {
AppDatabase.getDatabase(context).userDao().getAll();
}
});
return convertView;
}
}
Code for custom list item :
<pre>="1.0"="utf-8"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="16dp"
android:background="@color/white"
android:clickable="false"
android:orientation="horizontal">
<TextView
android:id="@+id/tvloltaskname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="3"
android:fontFamily="@font/roboto"
android:gravity="center_horizontal"
android:text="subtask_name"
android:textColor="@color/black"
android:textSize="15sp" />
<ImageView
android:id="@+id/ivlolPri"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_weight="1"
app:srcCompat="@drawable/priority_high" />
<ImageView
android:id="@+id/ivlolTime"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_weight="1"
app:srcCompat="@drawable/time_symbol_more" />
</LinearLayout>
What I have tried:
I have never done this before, this is my first time. So please pardon me if I made a silly mistake.