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

  • Home
  • SEARCH
  • 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 7999953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:39:08+00:00 2026-06-04T15:39:08+00:00

In my main activity, I have an ActionBar with navigation tabs and action items.

  • 0

In my main activity, I have an ActionBar with navigation tabs and action items. One of my action items calls a ListFragment that displays a custom listview with an image and textview. I’m using ActionBarSherlock for compatability. Here is the code where I call the new ListFragment:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent intent = new Intent(this, ERGProActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;
    case R.id.menuitem_search:
        onSearchRequested();
        return true;
    case R.id.menuitem_info:
        // Create new fragment and transaction
        SherlockListFragment aboutListFragment = new AboutListFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack
        ft.replace(R.id.root, aboutListFragment);
        ft.addToBackStack(null);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Commit the transaction
        ft.commit();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

Here is my ListFragment code:

public class AboutListFragment extends SherlockListFragment {

    private ListView listView;

    @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         getActivity().setContentView(R.layout.aboutlist);

         CustomMenu menu_data[] = new CustomMenu[]
                { new CustomMenu(R.drawable.info, "About"),
                  new CustomMenu(R.drawable.legal, "Disclaimer"),};

                CustomMenuAdapter adapter = new CustomMenuAdapter(getActivity(), 
                        R.layout.listview_item_row, menu_data);
                listView = (ListView) getActivity().findViewById(R.id.listView1);
                listView.setAdapter(adapter);
     }

     @Override
     public void onListItemClick(ListView l, View v, int position, long id) {
         switch (position) {
         case 0:
             // about
             Log.i("ABOUT"," - About Selected");
         case 1:
             Log.i("ABOUT"," - Disclaimer Selected");
             // disclaimer
         }
     }
}

Here is my CustomAdapter code:

public class CustomMenuAdapter extends ArrayAdapter<CustomMenu> {
    Context context; 
    int layoutResourceId;    
    CustomMenu data[] = null;

    public CustomMenuAdapter(Context context, int layoutResourceId, CustomMenu[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

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

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new CustomMenuHolder();
            holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);

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

        CustomMenu menu = data[position];
        holder.txtTitle.setText(menu.title);
        holder.imgIcon.setImageResource(menu.icon);

        return row;
    }

    static class CustomMenuHolder
    {
        ImageView imgIcon;
        TextView txtTitle;
    }
}

Any input or suggestions would be appreciated! Thanks in advanced.

Thanks everyone for your input! Here is the final working code:

 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
     super.onActivityCreated(savedInstanceState);
     getActivity().setContentView(R.layout.aboutlist);

     CustomMenu menu_data[] = new CustomMenu[]
            { new CustomMenu(R.drawable.info, "About"),
              new CustomMenu(R.drawable.legal, "Disclaimer"),};

            CustomMenuAdapter adapter = new CustomMenuAdapter(getActivity(), 
                    R.layout.listview_item_row, menu_data);
            listView = (ListView) getActivity().findViewById(R.id.listView1);
            // listView.setOnItemSelectedListener(this);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new OnItemClickListener() {

                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                    switch (position) {
                             case 0:
                                 Log.i("ABOUT"," - About Selected");
                                 break;
                             case 1:
                                 Log.i("ABOUT"," - Disclaimer Selected");
                                 break;
                             default:
                                 // do nothing
                                 Log.i("ABOUT"," - default");
                                 break;
                                }
                    }
            });
    }
  • 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-04T15:39:10+00:00Added an answer on June 4, 2026 at 3:39 pm
    listView.setOnItemClickListener(new OnItemClickListener() {
    
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub
    
                }
            });
    

    try with this code.

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

Sidebar

Related Questions

I have an activity with the following items: Action bar (one imageview, one view
i have main activity in which i have Four menus. and i have one
I have a design of activities like this I have one main activity and
If I have a login screen and then the activity which displays the main
I have a widget that supposed to call an Activity of the main app
Im building a contact application. In the main activity i have a listview, where
I have my main Activity, it starts with a custom SurfaceView called DrawView being
I have two activities, one is main and I have another activity called Test
I have a ListView on main activity, which shows a Contact picture on the
I have an Android application for pre-Honeycomb devices that uses custom tabs to launch

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.