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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:18:37+00:00 2026-06-10T05:18:37+00:00

In my application, I want to have a different background to the item which

  • 0

In my application, I want to have a different background to the item which is selected in the ListView. In fact I don’t have a plain ListView, its ListFragment out of which I am getting my ListView through getListView() method. I applied the selector programmatically like:

ListView listview = getListView();
listview.setSelector(R.drawable.tablet_settings_list_selector);

And the list selector xml is like,

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_focused="false"
    android:drawable="@drawable/tablet_menu_panel" />
<item android:state_pressed="true" android:state_focused="true"
    android:drawable="@drawable/tablet_menu_panel_ontap" />
<item android:state_activated="true"
    android:drawable="@drawable/tablet_selected_menu" />
</selector>

This is how my list should look like:

ListView with different background for selected item

As you can see, the selected list item has different background with an outward arrow to it. So how can I achieve this?

  • 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-10T05:18:38+00:00Added an answer on June 10, 2026 at 5:18 am

    Finally I made a conclusion that you can not set an item selected for ever in a ListView or ListFragment. So for that, I wrote my custom BaseAdapter and solved my problem 🙂
    For people facing similar issue, here is my BaseAdapter, focus on the getView() method.

    public class ListFragmentListAdapter extends BaseAdapter {
    
    String[] items;
    Context _context = null;
    private TabletFragment _tabletFragmentChild;
    
    public ListFragmentListAdapter(Context context, TabletFragment tabletFragmentChild, String[] items) {
        this.items = items;
        this._context = context;
        this._tabletFragmentChild = tabletFragmentChild;
    }
    
        //---------------------MOST IMPORTATNT PART----------------------
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(_context).inflate(R.layout.tablet_listfragment_list_item, null);
        }
    
        TextView textview = (TextView) convertView.findViewById(R.id.tv_listfragment_list_item);
        textview.setText(items[position]);
    
        convertView.setBackgroundDrawable(null);
        textview.setTextColor(_context.getResources().getColor(R.color.white));
    
        if(position == _tabletFragmentChild.getSelectedItemIndex()){
            convertView.setBackgroundResource(R.drawable.tablet_selected1_menu);
            textview.setTextColor(Color.BLACK);
        }
        return convertView;
    }
        //------------------------END OF IMP PART0------------------------
    
    @Override
    public long getItemId(int position) {
    
        return position;
    }
    
    @Override
    public Object getItem(int position) {
        return items[position];
    }
    
    @Override
    public int getCount() {
    
        if (items == null)
            return 0;
    
        return items.length;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am creating an application in which i want set different background images in
Scenario I have a windows forms application. I want to use two different WCF
I want my application to have a zoomable element which will allow the XAML
i m developing application in which i have to change the background image on
Background: I have an application written in native C++ which uses the wxWidgets toolkit's
In my application I need to have periodically run background tasks (which I can
In my application I want to have one view that holds 2 partial views.
I have a game server application (Java) and want to have PHP communicate directly
I want to have functionality on my application that lets a user check off
I want to have a one-click excel export feature for my application. I therefore

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.