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 8165225
In Process

The Archive Base Latest Questions

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

I’m trying to create a custom ArrayAdapter to use for my ListFragment . Right

  • 0

I’m trying to create a custom ArrayAdapter to use for my ListFragment. Right now nothing is being displayed in the ListFragment except for the TextView saying what Fragment number it is. I have put a breakpoint in getView() method of my adapter and it is not being called. I searched for reasons that wouldn’t be called and some people seem to think that my ListView is hidden, so I’ve tried changing the layout_height to wrap_content, but that didn’t work.

Also, I’ve been following the code from this developer’s page: http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html

ListFragment:

public class HomeFragment extends ListFragment implements FragmentTitle
{
private int mNum = 0;
private String mTitle = "Home";
private ListView mListView;
private MyArrayAdapter mAdapter;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    mNum = getArguments() != null ? getArguments().getInt("num") : 1;
    InfoContainer temp = new InfoContainer("test1", "test2");
    mAdapter = new MyArrayAdapter(getActivity(), android.R.id.list, temp);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    View v1 = inflater.inflate(R.layout.fragment_pager_list, container, false);
    TextView tv = (TextView) v1.findViewById(R.id.text);
    tv.setText("Fragment #" + mNum);
    mListView = (ListView) v1.findViewById(android.R.id.list);
    return v1;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) 
{
    super.onActivityCreated(savedInstanceState);
    mListView.setAdapter(mAdapter);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) 
{
    Log.i("HomeFragment", "Item clicked: " + id);
}

public CharSequence getTitle() 
{
    return mTitle;
}

}

ArrayAdapter:

public class MyArrayAdapter extends ArrayAdapter<InfoContainer>
{
Context mContext;
InfoContainer data;

public MyArrayAdapter(Context context, int textViewResourceId, InfoContainer temp) 
{
    super(context, textViewResourceId);
    mContext = context;
    this.data = temp;
}

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

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
        row = inflater.inflate(R.id.pager, parent, false);
        holder.v1 = (TextView) row.findViewById(R.id.listview_name);
        holder.v2 = (TextView) row.findViewById(R.id.listview_data);
        row.setTag(holder);
    }
    else
    {
        holder = (ViewHolder) row.getTag();
    }
    InfoContainer info = data;
    holder.v1.setText(info.name);
    holder.v2.setText(info.text);
    return row;
}

public static class ViewHolder
{
    TextView v1;
    TextView v2;
}

}

fragment_pager_list.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000" >

<TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal"
    android:text="@string/hello_world"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#FFFFFF" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false"
        android:background="@drawable/listview_background"
        android:textColor="#FFFFFF" />

I’ve made custom ArrayAdapters before with no problem, so is there something I’m missing about getting them to work with a ListFragment?

  • 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-06T19:29:17+00:00Added an answer on June 6, 2026 at 7:29 pm

    The solution is that getCount() was returning 0 for my ArrayAdapter. So I just used mAdapter.add(temp) and then mAdapter.notifyDataSetChanged() and it worked. I also had to change the line row = inflater.inflate(R.id.pager, parent, false); to row = inflater.inflate(R.layout.listview_row, parent, false);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.