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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:34:22+00:00 2026-06-18T07:34:22+00:00

I have a listview for my menu with a baseadapter. My Activity : listView_menu

  • 0

I have a listview for my menu with a baseadapter.

My Activity :

listView_menu = (ListView) findViewById(R.id.listView_menu);
model_category = new Model_Category(context);
listView_menu.setAdapter(new BaseAdapter_Menu(context, model_category.GetAllDifferentCategory()));
listView_menu.setOnItemClickListener(new OnItemClickListener() 
    {
        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3)
        {
            view.setSelected(true);
        }
    });
listView_menu.setSelection(0);

My getView method of BaseAdapter_Menu (extends BaseAdapter) :

@Override
public View             getView(int position, View convertView, ViewGroup parent)
{
    View                rowView = convertView;

    if (rowView == null)
    {
        rowView = this.inflater.inflate(R.layout.customitemlistview_menu, null);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.category = (TextView) rowView.findViewById(R.id.category_menu);
        rowView.setTag(viewHolder);
    }
    ViewHolder holder = (ViewHolder)rowView.getTag();
    holder.category.setText(this.data.get(position));
    return (rowView);
}

Each item has a selector for its background with 2 differents background depending of its state (SELECTED or NOT).

When I click on an item in my listview, I set to my view item.setSelected("true").

So when I click, the item’s background changes, but how to change the background of the first item of my listview without clicking on it.
I have already tried ‘listView_menu.setSelection(0)’ but it doesn’t work.

  • 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-18T07:34:23+00:00Added an answer on June 18, 2026 at 7:34 am

    I found the solution ! 🙂

    In my onCreate I appy this code :

    listView_menu.setAdapter(new BaseAdapter_Menu(context, model_category.GetAllDifferentCategory()));
        listView_menu.setOnItemClickListener(new OnItemClickListener() 
        {
            @Override
            public void onItemClick(AdapterView<?> listView, View view, int position, long id)
            {
                ((BaseAdapter_Menu) listView_menu.getAdapter()).setPositionSelected(position);
            }
        });
    

    In my BaseAdater_Menu :

    I create private int PositionSelected = 0;

    I add this method

    public void setPositionSelected(int position)
    {
        PositionSelected = position;
        this.notifyDataSetChanged();
    }
    

    And I override the getView method

    public View getView(int position, View convertView, ViewGroup parent)
    {
        View rowView = convertView;
    
        if (rowView == null)
        {
            rowView = this.inflater.inflate(R.layout.customitemlistview_menu, null);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.category = (TextView) rowView.findViewById(R.id.category_menu);
            rowView.setTag(viewHolder);
        }
        ViewHolder holder = (ViewHolder)rowView.getTag();
        holder.category.setText(this.data.get(position));
        if (position == PositionSelected)
            rowView.setBackgroundResource(R.drawable.item_menu_selected_background);
        else
            rowView.setBackgroundResource(R.drawable.item_menu_background);
        return (rowView);
    }
    

    Thank you for your help 🙂

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

Sidebar

Related Questions

I am extending BaseAdapter to make a custom listview row. I have context menu
so I have attached a context menu (right-click menu) to a wpf listview. unfortunately,
I have a listview with two columns and I'm using a context menu to
I have a ListView, which can either have a context menu, or not. I
I have a ListView with a context menu where the user can take a
ListView menuList = (ListView) findViewById(R.id.ListView_Menu); String[] items = {getResources().getString(R.string.menu_item_NxtInc)}; ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item,items);
I have a ListView whereby I want to display one context menu if an
I use ListView to populate my Menu and Price. I have 2 ListView s
I have a list view filled with data. I set up a context menu
I have a ListView which is supposed to become a menu with two drawables

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.