Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – What superclass should I choose for my Adapter Class?

Posted on November 11, 2022 By

Solution 1 :

Your Adapter class should almost always extend ListAdapter. Here’s a very basic example.

Problem :

I am making a time table app. In that app, each row is a CardView that has three columns – index, task’s name, total hours spent on that task. index is a TextView, task name and total hours spent are EditView. I want to transfer each row’s data through an adapter. I am unsure which super class to pick for the Adapter class based on my widgets I have chosen.

This is the main screen that shows all the rows of the time table –

    package com.example.timetable;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class TimeTable extends AppCompatActivity {

    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;
    private RecyclerView.LayoutManager layoutManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.time_table);

        List<cellProperties> cells = new ArrayList<>();


        //adapter should come here

        findViewById(R.id.add).setOnClickListener(view -> {

        });



    }
}

Here is the xml of file of the layout of the main screen –

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools_context=".TimeTable"
    android_orientation="vertical"
    android_padding="10dp"
    android_layout_margin="10dp">

    <androidx.recyclerview.widget.RecyclerView
        android_id="@+id/list"
        android_layout_width="match_parent"
        android_layout_height="0dp"
        android_layout_weight="1"
        app_layout_constraintBottom_toBottomOf="parent"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintStart_toStartOf="parent"
        app_layout_constraintTop_toTopOf="parent" />


    <Button
        android_id="@+id/add"
        android_layout_width="38dp"
        android_layout_height="wrap_content"
        android_text="+"
        android_layout_gravity="center_horizontal"
        >

    </Button>
</LinearLayout>

Here is a sample of each row (I will add this row into my main screen)-

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns_android="http://schemas.android.com/apk/res/android"
    android_layout_width="match_parent"
    android_layout_height="wrap_content"
    xmlns_app="http://schemas.android.com/apk/res-auto"
    android_layout_margin="10dp"
    app_cardCornerRadius="10dp"
    app_cardElevation="5dp"
    app_contentPadding="10dp">

    <LinearLayout
        android_layout_width="match_parent"
        android_layout_height="match_parent"
        android_orientation="horizontal">

        <TextView
            android_id="@+id/index"
            android_layout_width="0dp"
            android_layout_height="wrap_content"
            android_textSize="18sp"
            android_layout_weight="0.125"
            android_text="1."
            android_textAlignment="center">

        </TextView>

        <EditText
            android_id="@+id/taskName"
            android_layout_width="0dp"
            android_layout_height="wrap_content"
            android_textSize="18sp"
            android_layout_weight="0.625"
            android_hint="Enter Task's name"
            android_inputType="text">

        </EditText>

        <EditText
            android_id="@+id/totalHours"
            android_layout_width="0dp"
            android_layout_height="wrap_content"
            android_textSize="18sp"
            android_layout_weight="0.25"
            android_hint="Total Time"
            android_inputType="time">

        </EditText>
    </LinearLayout>
</androidx.cardview.widget.CardView>

Comments

Comment posted by Community

Please provide enough code so others can better understand or reproduce the problem.

READ  [FIXED] android - Google Play Alert- App using unsafe implementation of the hostnameVerifier
Powered by Inline Related Posts

Comment posted by Jezues

Hey! sorry for a late response, but here is the code as needed. Edit – I want to know which adapter class I should use.

Android Tags:android, android-adapter, android-recyclerview, java

Post navigation

Previous Post: [FIXED] Android ACTION_VIEW intent is not opening urls in non-browser apps like twitter and instagram
Next Post: [FIXED] android – Check if activity is active, and if active pass data from service to activity?

Related Posts

[FIXED] android – .findViewById() returns null Android
[FIXED] High/Critical Security Risk in (platform frameworks base android-9.0.0_r10) – CVE-2019-9468 Android
[FIXED] java – Cancelling multiple notification by sending unique id to broadcast receiver Android
[FIXED] java – Android 11 doesn’t create app directory on internal storage Android
[FIXED] How to use GoogleDrive from Android app using FireBase Auth UI? Android
[FIXED] android – SoftKeyboard hide views even if “adjustResize” or “adjustPan” has been set in the manifest Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme