question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Adapter instead of Array Adapter?

See original GitHub issue

Hi,

I’ve created a custom adapter to use with my object rather than the simple ArrayAdapter since I need some extra fields, however, not all of my custom fields are showing up on the swipecard.

With the following code the title, company name and description fields are correctly populated onto my card but not the others, even though the fields are there. No errors from the debugger and everything works fine but they just don’t show up!!! What am I missing?

Here is what I am doing in my activity:

At the top of the activity: @InjectView(R.id.frame) SwipeFlingAdapterView flingContainer;

In my AsyncTask:

arrayAdapter = new JobAdapter(getApplicationContext(), R.layout.jobcard, result);
flingContainer.setAdapter(arrayAdapter);

Yes: the result ArrayList is populated with values.

My adapter:


public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder = null;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService((Activity.LAYOUT_INFLATER_SERVICE));

        if (row == null) {
            row = inflater.inflate(layoutResourceId, parent, false);
            //row = inflater.inflate(layoutResourceId, null);

            holder = new ViewHolder();
            holder.title = (TextView)row.findViewById(R.id.tv_jobTitle);
            holder.payrate = (TextView)row.findViewById(R.id.tv_payRate);
            holder.startdate = (TextView)row.findViewById(R.id.tv_startDate);
            holder.workinghrs = (TextView)row.findViewById(R.id.tv_duration);
            holder.location = (TextView)row.findViewById(R.id.tv_location);
            holder.companyname = (TextView)row.findViewById(R.id.tv_companyName);
            holder.description = (TextView)row.findViewById(R.id.tv_JobDesc);
            holder.equipment = (TextView)row.findViewById(R.id.tv_equipmentReq);
            holder.experience = (TextView)row.findViewById(R.id.tv_experienceReq);

            row.setTag(holder);
        } else {
            holder = (ViewHolder)row.getTag();
        }

        Job j = jobs.get(0);

        holder.title.setText(j.getJobTitle());
        holder.payrate.setText(j.getPayrate());
        holder.startdate.setText(j.getDurationStart());
        holder.workinghrs.setText(j.getWorkingHrs());
        holder.location.setText(j.getLocation());
        holder.companyname.setText("ABC Company");
        holder.description.setText(j.getDescription());
        holder.equipment.setText("Hardhat");
        holder.experience.setText("3-5 years");

        return row;
    }
    static class ViewHolder
    {
        TextView title;
        TextView payrate;
        TextView startdate;
        TextView workinghrs;
        TextView location;
        TextView companyname;
        TextView description;
        TextView equipment;
        TextView experience;
    }

And finally, my jobcard.xml layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:padding="20dp">

    <LinearLayout
        android:id="@+id/mainCardLayout"
        android:layout_width="match_parent"
        android:layout_height="340dp"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:weightSum="1"
        android:background="#ffffff">

        <TextView
            android:id="@+id/tv_jobTitle"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textStyle="bold"
            android:textSize="16sp"
            android:textColor="#474747"
            android:textAlignment="center"
            tools:text="Cement Pouring Guy"
            android:layout_gravity="center_horizontal"/>

        <TextView
            android:id="@+id/tv_companyName"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:textColor="#474747"
            android:textAlignment="center"
            tools:text="ABC Company"
            android:layout_gravity="center_horizontal" />

        <LinearLayout
            android:id="@+id/cardHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp">

            <TextView
                android:id="@+id/tv_experienceReq"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginLeft="10dp"
                tools:text="3-5 years" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/tv_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                tools:text="Langley, BC" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/tv_payRate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginRight="10dp"
                tools:text="125/day" />

        </LinearLayout>

        <TextView
            android:id="@+id/tv_JobDesc"
            android:textSize="14sp"
            android:textColor="#474747"
            android:background="#f3f3f3"
            tools:text="Pour Cement, Mix Cement, Level Cement and go pick up cement bags."
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:padding="15dp" />

        <LinearLayout
            android:id="@+id/additionalInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >

            <TextView
                android:id="@+id/tv_startDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginLeft="10dp"
                tools:text="June 1, 2016" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                />

            <TextView
                android:id="@+id/tv_duration"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                tools:text="8h" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                />

            <TextView
                android:id="@+id/tv_equipmentReq"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginRight="10dp"
                tools:text="Hardhat" />

        </LinearLayout>

    </LinearLayout>

    <View
        android:id="@+id/item_swipe_left_indicator"
        android:alpha="0"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="20dp"
        android:background="#A5F" />

    <View
        android:id="@+id/item_swipe_right_indicator"
        android:alpha="0"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="20dp"
        android:layout_gravity="right"
        android:background="#5AF" />

</FrameLayout>

Thanks for the help!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
thofnarcommented, Apr 14, 2016

@alexwalterbos well I figured it out and I feel like an idiot haha. Turns out I didn’t define a text color in my xml file so the fields were being populated but with white text so I couldn’t see the values. After changing the color, the adapter works fine 😃. Thanks for the help!

0reactions
alexwalterboscommented, Apr 14, 2016

Haha it happens to the best. No problem!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Array Adapters made Easy! - Medium
So I have created a sample project called Popular Movies in which we will create a custom array adapter which which will help...
Read more >
Custom ArrayAdapter with ListView in Android - GeeksforGeeks
Custom ArrayAdapter with ListView in Android · Step 1: Create an Empty Activity project · Step 2: Working with the activity_main. · Step...
Read more >
Using an ArrayAdapter with ListView - CodePath Cliffnotes
We can create a custom ListView of User objects by subclassing ArrayAdapter to describe how to translate the object into a view within...
Read more >
how to create a custom array adapter in android studio to ...
Instead of using a regular ListView use a custom one: 1) Create a CustomListView class: public class CustomListView extends ListView{ //add ...
Read more >
Android ListView with Custom Adapter Example Tutorial
In this tutorial we'll use a CustomAdapter that populates the custom rows of the Android ListView with an ArrayList .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found