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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:51:22+00:00 2026-06-10T01:51:22+00:00

Im trying to use a list fragment embedded in a parent fragment via layout

  • 0

Im trying to use a list fragment embedded in a parent fragment via layout XML (I’ve also done through fragment manager with no change). When I embed the listfragment by itself I am able to see the content from the cursor. When I override onCreateView of the parent fragment (ShoppingListActivity) and return a custom view I am no longer able to see my list fragment content.

On the list fragment I’m using a CursorLoader and onLoadFinished always called with a cursor that has content so it’s not a matter of data not being present when I use the custom layout on the parent fragement combined. The listfragment doesn’t have a custom layout (I originally started with the buttons from the parent fragment being added by overriding onCreateView of the list fragment but that produced the same result)

I also originally started out using the support library for the fragments but now use the native fragments.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
 <Button
    android:id="@+id/btn_shopping_list_add_item_manually"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/btn_shopping_list_add_item_barcode"
    android:onClick="addItemManually"
    android:text="TYPE"
    />

<Button
    android:id="@+id/btn_shopping_list_add_item_barcode"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:onClick="addItemFromBarcode"
    android:text="SCAN"
    />
<fragment     android:name="com.ainesophaur.shopping.assistant.fragments.ShoppingListFragment"
    android:id="@+id/list"
    android:layout_height="0dp"
    android:layout_below="@+id/btn_shopping_list_add_item_manually"
    android:layout_alignParentLeft="true"
    android:layout_width="fill_parent" />

—Edit—-

Since I cannot upload images yet Ill draw what happens

When onCreateView is over ridden and a custom view is provided (The above XML layout) I get

Button1 Button2

Nothing

When I call the listview fragment directly I get

List Item1
List Item2

The list view fragment has a custom adapter extended from CursorAdapter and when I have the above specified XML layout returned from onCreateView then my newView and bindView of the adapter aren’t called.

I’ve also tried to include a listview item in the parent fragment XML (instead of including the fragment itself) and gave it the standard android ID of list and I still get the same result..if I give the list view a unique ID and call setAdapter on the list then I also get no result (ie, bindView and newView of the adapter never get called) after onLoadFinished of the cursorloader
—EDIT

Now I can upload images 🙂

Missing List

List Shown


This is the code that contains the ListFragment and the CursorAdapter

ListFragment

public class ShoppingListFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
    private int mStoreID;
    private long mListID;
    private String mStoreName;
    private ShoppingListItemsAdapter adapter;
    private Context mContext;
    private Cursor mCursor;
    private static final int SHOPPING_LIST_LOADER = 0x04;

     CursorLoader cursorLoader;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
        Bundle args = getArguments();
        mListID = 4; //args.getLong("listid");
        //mStoreName = args.getString("storename");

    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mContext = getActivity();
        adapter = new ShoppingListItemsAdapter(mContext, mCursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        setListAdapter(adapter);
        //setListAdapter(adapter);
        getLoaderManager().initLoader(SHOPPING_LIST_LOADER, null, this);
    }
    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        cursorLoader = new CursorLoader(getActivity(),
                 Uri.withAppendedPath(ShoppingListProvider.CONTENT_LIST_ITEMS_URI, String.valueOf(mListID)), ShoppingDBAdapter.joinitemProj, null, null, null);
        return cursorLoader;
    }
    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        adapter.swapCursor(cursor);
        //setListShown(true);
    }
    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        adapter.swapCursor(null);
    }

    private OnClickListener addManual = new OnClickListener() {

        @Override
        public void onClick(View v) {
            Fragment fragment = new AddItemFragment();
            Bundle args = new Bundle();
            args.putLong("listid", mListID);
            fragment.setArguments(args);
            getFragmentManager().beginTransaction()
            .replace(R.id.container, fragment).addToBackStack(null)
            .commit();

            return;

        }
    };
    private static class ShoppingListItemViewHolder {
        public TextView separator;
        public TextView itemQuantity;
        public TextView itemName;
        public TextView itemPrice;
        public CharArrayBuffer quantityObtainedBuffer = new CharArrayBuffer(128);
        public CharArrayBuffer quantityNeededBuffer = new CharArrayBuffer(128);
        public CharArrayBuffer titleBuffer = new CharArrayBuffer(128);
        public CharArrayBuffer priceBuffer = new CharArrayBuffer(128);
        public CharArrayBuffer itemCategoryBuffer = new CharArrayBuffer(128);
  }
    public void addItemFromBarcode(View v)
    {
        return;
    }

extended CursorAdapter

private static class ShoppingListItemsAdapter extends CursorAdapter
{
    private static final int STATE_UNKNOWN = 0;
    private static final int STATE_SECTIONED_CELL = 1;
    private static final int STATE_REGULAR_CELL = 2;
    String LAST_CATEGORYNAME = "";
    private final CharArrayBuffer mBuffer = new CharArrayBuffer(128);
    private int[] mCellStates;

    public ShoppingListItemsAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);
        mCellStates = (c == null) ? null : new int[c.getCount()];
    }
      @Override
        public void changeCursor(Cursor cursor) {
            super.changeCursor(cursor);
            mCellStates = (cursor == null) ? null : new int[cursor.getCount()];
        }
      @Override
        public Cursor swapCursor(Cursor cursor) {
            Cursor oldCursor = super.swapCursor(cursor);
            mCellStates = (cursor == null) ? null : new int[cursor.getCount()];
            return oldCursor;
        }
      @Override
        public void bindView(View view, Context context, Cursor cursor) {

          final ShoppingListItemViewHolder holder = (ShoppingListItemViewHolder) view.getTag();
          final int COLUMN_NAME_INDEX = cursor.getColumnIndex(ShoppingDBAdapter.KEY_NAME);
          final int COLUMN_ITEMCATEGORY_INDEX = cursor.getColumnIndex(ShoppingDBAdapter.KEY_CATEGORYID);
          final int COLUMN_PRICE_INDEX = cursor.getColumnIndex(ShoppingDBAdapter.KEY_PRICE);
          final int COLUMN_OBTAINED_INDEX = cursor.getColumnIndex(ShoppingDBAdapter.KEY_OBTAINED);
          final int COLUMN_NEEDED_INDEX = cursor.getColumnIndex(ShoppingDBAdapter.KEY_NEEDED);
          boolean needSeparator = false;  
          final int position = cursor.getPosition();
          cursor.copyStringToBuffer(COLUMN_NAME_INDEX, holder.titleBuffer);
          cursor.copyStringToBuffer(COLUMN_PRICE_INDEX, holder.priceBuffer);
          cursor.copyStringToBuffer(COLUMN_NEEDED_INDEX, holder.quantityNeededBuffer);
          cursor.copyStringToBuffer(COLUMN_ITEMCATEGORY_INDEX, holder.itemCategoryBuffer);
          switch (mCellStates[position]) 
             {
                  case STATE_SECTIONED_CELL:
                      needSeparator = true;
                      break;

                  case STATE_REGULAR_CELL:
                      needSeparator = false;
                      break;

                  case STATE_UNKNOWN:
                  default:
                      if (position == 0) {
                          if(holder.itemCategoryBuffer.sizeCopied > 0)
                          {
                              needSeparator = true;
                              int holderStoreNameSize = holder.itemCategoryBuffer.sizeCopied;
                              String holderStoreName = "";
                              for(int i = 0; i < holderStoreNameSize; i++)
                              {
                                  holderStoreName += holder.itemCategoryBuffer.data[i];
                              }
                              LAST_CATEGORYNAME = holderStoreName;
                          }
                      } 
                      else 
                      {
                          cursor.moveToPosition(position - 1);
                          cursor.copyStringToBuffer(COLUMN_ITEMCATEGORY_INDEX, mBuffer);
                          if (mBuffer.sizeCopied > 0 && holder.itemCategoryBuffer.sizeCopied > 0) 
                          {
                              int mBufferSize = mBuffer.sizeCopied;
                              int holderStoreNameSize = holder.itemCategoryBuffer.sizeCopied;
                              String mBufferName = "";
                              String holderStoreName = "";
                              for(int i = 0; i < holderStoreNameSize; i++)
                              {
                                  holderStoreName += holder.itemCategoryBuffer.data[i];
                              }
                              if(!LAST_CATEGORYNAME.equals(holderStoreName))
                              {
                                  needSeparator = true;
                                  LAST_CATEGORYNAME = holderStoreName;
                              }
                          }
                          cursor.moveToPosition(position);
                      }
                      mCellStates[position] = needSeparator ? STATE_SECTIONED_CELL : STATE_REGULAR_CELL;
                      break;
              }
          if (needSeparator) {
                holder.separator.setText(holder.itemCategoryBuffer.data, 0 , holder.itemCategoryBuffer.sizeCopied);
                holder.separator.setVisibility(View.VISIBLE);
            } else {
                holder.separator.setVisibility(View.GONE);
            }
            holder.itemName.setText(holder.titleBuffer.data, 0, holder.titleBuffer.sizeCopied);
            holder.itemPrice.setText(holder.priceBuffer.data, 0, holder.priceBuffer.sizeCopied);
            holder.itemQuantity.setText(holder.quantityNeededBuffer.data, 0, holder.quantityNeededBuffer.sizeCopied);
      }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
         View v = LayoutInflater.from(context).inflate(R.layout.fragment_shopping_list_items_row, parent, false);
         ShoppingListItemViewHolder holder = new ShoppingListItemViewHolder();
         holder.separator = (TextView)v.findViewById(R.id.separator);
         holder.itemName = (TextView)v.findViewById(R.id.item_name);
         holder.itemPrice = (TextView)v.findViewById(R.id.item_price);
         holder.itemQuantity = (TextView)v.findViewById(R.id.item_quantity);
         v.setTag(holder);
         return v;
    }
}
  • 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-10T01:51:23+00:00Added an answer on June 10, 2026 at 1:51 am

    Once I changed the layout XML used by the list view fragment from RelativeLayout to a LinearLayout I was able to see the items.

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

Sidebar

Related Questions

I'm having trouble trying to use a list in my activity. My XML for
I've been trying to use a List<> of a Model.Person that I have inside
I was trying to use an STL list in C++ and I arrived into
I am trying to use dynamically created list in WHERE, for example: select *
I'm trying to use templates to get std:list of items, where each item has
I am trying to use LINQ to return a list of tasks that are
I am trying to use UIMenuCnotroller to show a list of dynamically generated items,
I'm trying to use the .Contains() function on a list of custom objects. This
I am trying to use a linq expression to filter a list in a
I'm trying to use iglob instead of glob to get a list of say

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.