Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:00:29+00:00 2026-06-15T12:00:29+00:00

I have a Listview with a custom ArrayAdapter that is set inside of a

  • 0

I have a Listview with a custom ArrayAdapter that is set inside of a fragment. Only the first row in the ListView is being set.

This may be a common problem when using ListViews with fragments in general as I’ve followed the tutorials on custom ArrayAdapters from here to the letter (as far as I can tell).

MyFragment:

public class MyFragment extends Fragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment, container, false);

    ListView myListView = (ListView) v.findViewById(R.id.custom_listview);

    ArrayList<CustomRow> customList = new ArrayList<CustomRow>();
    customList.add(new CustomRow("Test A", "A", "AA");
    customList.add(new CustomRow("Test B", "B", "BB");
    customList.add(new CustomRow("Test C", "C", "CC");

    CustomAdapter customAdapter = new CustomAdapter(getActivity(), R.layout.listitem_custom, customList);
    myListView.setAdapter(customAdapter);

    //Inflate the layout for this fragment
    return v;

}

}

So even though three rows are added to the list, only the first ListItem says “Test A”, “A”, “AA”. The last two rows simply keep the text as defined in the layout (i.e. the text is never actually set to anything, not even null)

Custom ArrayAdapter

public class CustomAdapter extends ArrayAdapter<CustomRowItem> {

Context context;
ArrayList<CustomRowItem> rowList;

public CustomAdapter(Context context, int textViewResourceId, ArrayList<CustomRowItem> rowList) {
    super(context, textViewResourceId, rowList);
    this.context = context;
    this.rowList = rowList;
}

public static class ViewHolder {
    public TextView tvText1;
    public TextView tvText2;
    public TextView tvText3;
}

public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;

    // called when listview is not instantiated yet (first run)
    if (convertView == null) {

        // assigns the layout custom_row.xml as the listitem (a single row)
        LayoutInflater alarmInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = alarmInflater.inflate(R.layout.listitem_custom, null);

        holder = new ViewHolder();
        holder.tvText1 = (TextView) convertView.findViewById(R.id.textview1);
        holder.tvText2 = (TextView) convertView.findViewById(R.id.textview2);
        holder.tvText3 = (TextView) convertView.findViewById(R.id.textview3);

        convertView.setTag(holder);

    // called when list view is already instantiated and we are updating the fields
    } else {

        holder = (ViewHolder) convertView.getTag();

        CustomRowItem newRow = rowList.get(position);

        if (newRow != null) {

            holder.tvText1.setText(newRow.getText1());
            holder.tvText2.setText(newRow.getText2());
            holder.tvText3.setText(newRow.getText3());

        }

    }


    return convertView;
}

}

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:00:30+00:00Added an answer on June 15, 2026 at 12:00 pm

    the else statement in your getView() has more code than it should. this is how it should be:

    public View getView(int position, View convertView, ViewGroup parent) {
    
        ViewHolder holder;
    
        // called when listview is not instantiated yet (first run)
        if (convertView == null) {
    
            // assigns the layout custom_row.xml as the listitem (a single row)
            LayoutInflater alarmInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = alarmInflater.inflate(R.layout.listitem_custom, null);
    
            holder = new ViewHolder();
            holder.tvText1 = (TextView) convertView.findViewById(R.id.textview1);
            holder.tvText2 = (TextView) convertView.findViewById(R.id.textview2);
            holder.tvText3 = (TextView) convertView.findViewById(R.id.textview3);
    
            convertView.setTag(holder);
    
            // called when list view is already instantiated and we are updating the fields
        } else {
            holder = (ViewHolder) convertView.getTag(); // <-- that's all for here
        }
    
        CustomRowItem newRow = rowList.get(position);
        if (newRow != null) {
            holder.tvText1.setText(newRow.getText1());
            holder.tvText2.setText(newRow.getText2());
            holder.tvText3.setText(newRow.getText3());
        }
    
        return convertView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that has a custom ArrayAdapter with a custom XML row.
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have a custom listview row that contains a number of textView components. Instead
I have created a custom ArrayAdapter that fills a ListView . The data in
I have used ListView and bounded my custom ArrayAdapter to it. Have setOnItemClickListener(...) bound
I have a listview connected to a custom array adapter. This list shows information
I have a listview with custom row having a textview and a clickable image
I have used custom listview and custom rating bar. If I add that custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.