Question

Android Development: Help convert code to RecyclerView import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import...

Android Development: Help convert code to RecyclerView

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;


public class RolodexDataAdapter extends BaseAdapter {
    private ArrayList<Rolodex> rolodexArrayList;
    private LayoutInflater layoutInflater;

    public RolodexDataAdapter(Context context, ArrayList<Rolodex> dataList) {
        this.rolodexArrayList = dataList;
        this.layoutInflater = LayoutInflater.from(context);
    }

    private TextView getTextView(View view, int textViewId) {
        return (TextView) view.findViewById(textViewId);
    }

    @Override
    public int getCount() {
        return ((null != this.rolodexArrayList) ? this.rolodexArrayList.size() : 0);
    }

    @Override
    public Object getItem(int i) {
        if ((null != this.rolodexArrayList) && !this.rolodexArrayList.isEmpty()) {
            if ((i >= 0) && (i < this.rolodexArrayList.size()))
                return this.rolodexArrayList.get(i);
        }

        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        if (null == convertView) {
            convertView = this.layoutInflater.inflate(R.layout.rolodex_list_row, null);
            if (null == convertView)
                return null;
        }

        TextView textViewName = (TextView) convertView.findViewById(R.id.textViewName);
        TextView textViewPhone = (TextView) convertView.findViewById(R.id.textViewPhone);

        Rolodex rolodex = (Rolodex) this.getItem(position);
        if (null != rolodex) {
            textViewName.setText(rolodex.getFullName());
            textViewPhone.setText(rolodex.PhoneNumber);
            convertView.setTag(rolodex);
        } else {
            convertView.setTag(null);
        }

        return convertView;
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
the answer for this will not change to  recycler view

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;


public class RolodexDataAdapter extends BaseAdapter {
    private ArrayList<Rolodex> rolodexArrayList;
    private LayoutInflater layoutInflater;

    public RolodexDataAdapter(Context context, ArrayList<Rolodex> dataList) {
        this.rolodexArrayList = dataList;
        this.layoutInflater = LayoutInflater.from(context);
    }

    private TextView getTextView(View view, int textViewId) {
        return (TextView) view.findViewById(textViewId);
    }

    @Override
    public int getCount() {
        return ((null != this.rolodexArrayList) ? this.rolodexArrayList.size() : 0);
    }

    @Override
    public Object getItem(int i) {
        if ((null != this.rolodexArrayList) && !this.rolodexArrayList.isEmpty()) {
            if ((i >= 0) && (i < this.rolodexArrayList.size()))
                return this.rolodexArrayList.get(i);
        }

        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        if (null == convertView) {
            convertView = this.layoutInflater.inflate(R.layout.rolodex_list_row, null);
            if (null == convertView)
                return null;
        }

        TextView textViewName = (TextView) convertView.findViewById(R.id.textViewName);
        TextView textViewPhone = (TextView) convertView.findViewById(R.id.textViewPhone);

        Rolodex rolodex = (Rolodex) this.getItem(position);
        if (null != rolodex) {
            textViewName.setText(rolodex.getFullName());
            textViewPhone.setText(rolodex.PhoneNumber);
            convertView.setTag(rolodex);
        } else {
            convertView.setTag(null);
        }

        return convertView;
    }
}
Add a comment
Know the answer?
Add Answer to:
Android Development: Help convert code to RecyclerView import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help to edit the code below. Am using it play a lottery game in Android...

    Need help to edit the code below. Am using it play a lottery game in Android Studio what i need help with is if play one game u need to clear it up before u could another game. Here is my activity_main.xml <?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="simpleapps.my.lotteryapplication.MainActivity" android:orientation="vertical" android:layout_margin="10dp" android:weightSum="100"> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:text="Enter White Balls : " android:textColor="#000000" android:textSize="22sp" android:layout_weight="15" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:weightSum="100" android:layout_margin="10dp" android:layout_weight="15"> <EditText android:id="@+id/wBall1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="20" android:inputType="number"/>...

  • Need help to edit the code below. Am using it play a lottery game in Android...

    Need help to edit the code below. Am using it play a lottery game in Android Studio what i need help with is if play one game u need to clear it up before u could another game. Here is my activity_main.xml <?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="simpleapps.my.lotteryapplication.MainActivity" android:orientation="vertical" android:layout_margin="10dp" android:weightSum="100"> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:text="Enter White Balls : " android:textColor="#000000" android:textSize="22sp" android:layout_weight="15" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:weightSum="100" android:layout_margin="10dp" android:layout_weight="15"> <EditText android:id="@+id/wBall1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="20" android:inputType="number"/>...

  • Need help to build a fingerprint app that we have sslserversocket to tell a file use finger print...

    need help to build a fingerprint app that we have sslserversocket to tell a file use finger print before open the file what have been done below Here is my mainactivity.java and fingerprintHandler.java below <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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=".MainActivity"> <TextView android:id="@+id/heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:padding="20dp" android:text="Fingerprint Authentication" android:textAlignment="center" android:textColor="@android:color/black" android:textSize="18sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.0" /> <TextView android:id="@+id/paraMessage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="Place your finger on the fingerprint scanner to...

  • I should show tables with info after clicking on the buttons in Android Studio. I still...

    I should show tables with info after clicking on the buttons in Android Studio. I still can not get what I should write inside OnClick function and how to use containers for printing tables. Please help me! import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.os.Bundle; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { LinearLayout container; ListView ListView1; ListView ListView2; ListView ListView3; @Override protected void onCreate(Bundle savedInstanceState)...

  • Java help! Please help complete the min method below in bold. import java.util.Arrays; import java.util.ArrayList; import...

    Java help! Please help complete the min method below in bold. import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * Provides an implementation of a binary search tree * with no balance constraints, implemented with linked nodes. * * * */ public class Bst<T extends Comparable<T>> implements Iterable<T> { ////////////////////////////////////////////////////////////////// // I M P L E M E N T T H E M I N M E T H O D B E L O W...

  • What is the output of the following program? import java.util.ArrayList; import java.util.Collections; import java.util.List; public class...

    What is the output of the following program? import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test implements Comparable<Test> private String[] cast; public Test( String[] st) cast = st; public int compareTo( Test t) if ( cast.length >t.cast.length ) t return +1; else if cast.length < t.cast.length return -1; else return 0; public static void main( String[] args String[] a"Peter", "Paul", "Mary" String[] b_ { "Мое", ''Larry", "Curly", String [ ] c = { ·Mickey", "Donald" }; "Shemp" }; List<Test>...

  • I am working on integrating a database to an Android application for a course. Currently, I have all the database code done, but getting all of the EditText fields to enter data into the database has...

    I am working on integrating a database to an Android application for a course. Currently, I have all the database code done, but getting all of the EditText fields to enter data into the database has me stuck. Assignment objectives here, so we can be on the same page: Create a second page with a data entry form and the following fields: recipename, category, ingredients, and instructions. Make the Category field a dropdown box that contains the recipe categories listed...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • How can I make a test case with Junit? import java.util.ArrayList; import board.Board; public class Pawn...

    How can I make a test case with Junit? import java.util.ArrayList; import board.Board; public class Pawn extends Piece{    public Pawn(int positionX, int positionY, boolean isWhite) {        super("P", positionX, positionY, isWhite);    }    @Override    public String getPossibleMoves() {        ArrayList<String> possibleMoves = new ArrayList<>();               //check side, different color pawns go on different ways        if(isWhite) {            if(positionX != 7 && positionY != 0) {           ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT