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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:44:45+00:00 2026-05-24T03:44:45+00:00

I’m learning how to use the new Fragment classes and have run across a

  • 0

I’m learning how to use the new Fragment classes and have run across a situation that I can’t find an answer to.

I have a listener set up so that when an item is clicked in a list fragment that item is supposed to be reflected in a GridView in another fragment.

Here is the listener:

public void onBulkScanAttributesFragmentListItemClicked(View v)
{
    TextView nameID = (TextView) v.findViewById(R.id.list_item_with_checkbox_dialog_item_name);
    String name = (String) nameID.getText();
    String value = "Set value";

    if (!names.contains(name))
    {
        names.add(name);
        items.add(new Row(name, value));
    }

    for (Row row : items)
    {
        Log.d(TAG, row.getRowName());
        Log.d(TAG, row.getRowValue());
    }
    BulkScanChosenAttributes chosen = new BulkScanChosenAttributes(items);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.chosen_att_fragment, chosen);
    transaction.commit();
}

Here are the constructors and onActivityCreate and onCreateView methods from the fragment with the GridView:
public class BulkScanChosenAttributes extends Fragment
{
private static final String TAG = “BulkScanChosenAttributes”;
private ArrayList items;
private GridAttributeAdapter adapter;

public BulkScanChosenAttributes()
{
    items = null;
}

public BulkScanChosenAttributes(ArrayList<Row> items)
{
    this.items = items;
}

@Override
public void onActivityCreated(Bundle savedInstance)
{
    super.onActivityCreated(savedInstance);

    adapter = new GridAttributeAdapter(getActivity(), items);

    if (items != null)
    {
        LayoutInflater gridInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = gridInflater.inflate(R.layout.bulk_scan_chosen, null);
        GridView gridView = (GridView) v.findViewById(R.id.gridview);

        gridView.setAdapter(adapter);
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{ 
    if (adapter != null)
        adapter.notifyDataSetChanged();
    return inflater.inflate(R.layout.bulk_scan_chosen, container, false); 
}

Here is the XML layout for the GridView (R.layout.bulk_scan_chosen):

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
  android:id="@+id/gridview"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:columnWidth="90dp"
  android:numColumns="auto_fit"
  android:verticalSpacing="10dp"
  android:horizontalSpacing="10dp"
  android:stretchMode="columnWidth"
  android:gravity="center" />

The XML layout for the view in the GridView (R.layout.grid_item_layout):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <TextView
    android:id="@+id/grid_att_name"
    android:layout_width = "fill_parent"
    android:layout_height = "wrap_content"
    android:textColor = "@color/black"
    android:textSize = "@dimen/font_large"
    android:textStyle = "bold"
    android:gravity = "center_horizontal" />
  <TextView
    android:id="@+id/grid_att_value"
    android:layout_width = "fill_parent"
    android:layout_height = "wrap_content"
    android:textColor = "@color/black"
    android:textSize = "@dimen/font_large"
    android:textStyle = "bold"
    android:gravity = "center_horizontal" />
</LinearLayout>

(This is getting long!) And finally, my adapter:

public class GridAttributeAdapter extends BaseAdapter
{
    private int count;
    private LayoutInflater inflater;
    private Context context;
    private String name;
    private String value;
    private ArrayList<Row> items;

    public GridAttributeAdapter(Context context, ArrayList<Row> items)
    {
        int count = 0;
        this.context = context;
        this.items = items;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount()
    {
        return count;
    }

    @Override
    public Object getItem(int position)
    {
        return position;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View v = convertView;
        //try to inflate the view
        try
        {
            v = inflater.inflate(R.layout.grid_item_layout, null);
        }
        catch (NullPointerException npe)
        {
            npe.printStackTrace();
            Log.e(TAG, "view is null");
        }

        Row row = items.get(position);

        try
        {
            TextView name = (TextView) v.findViewById(R.id.grid_att_name);
            TextView value = (TextView) v.findViewById(R.id.grid_att_value);

            if (ListMetaData.withDates.contains(ListMetaData.reverseScreenNames.get(row.getRowName())))
            {
                try
                {
                    Date date = new Date(new Long(row.getRowValue()));
                    value.setText(date.getMonth() + "/" + date.getDate() + "/" + date.getYear());
                }
                catch (NumberFormatException nfe)
                {
                    value.setText(row.getRowValue());
                }
            }
            else
            {
                value.setText(row.getRowValue());
            }

            name.setText(row.getRowName());
        }
        catch (NullPointerException npe)
        {
            npe.printStackTrace();
            Log.e(TAG, "something went wrong in TextView assignment");
        }

        return v;
    }

}

The adapter is declared within BulkScanChosenAttributes.

The BulkScanChosenAttributes fragment that I want to be updated is blank. I’ve checked to make sure that the code is executing, but I’m still a little shaky on Fragments. Any help would be greatly appreciated.

  • 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-05-24T03:44:46+00:00Added an answer on May 24, 2026 at 3:44 am

    The problem was in my BaseAdapter implementation. The getCount method was returning 0. After fixing that, it worked as expected.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
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,

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.