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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:13:38+00:00 2026-06-09T06:13:38+00:00

I have a ListView with an OnItemClickListener where I’m setting the background to indicate

  • 0

I have a ListView with an OnItemClickListener where I’m setting the background to indicate the row has been selected

itemList.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {

        String item = (String) arg0.getItemAtPosition(position);
        boolean itemSelected = selectedItems.contains(item);

        if (!itemSelected) {
            selectedItems.add(item);
            v.setBackgroundDrawable(getResources().getDrawable(R.drawable.listitem_selected));
        } else {
            selectedItems.remove(item);
            v.setBackgroundDrawable(null);
        }
    });

If I use a default adapter for my ListView, the ListView row is properly highlighted

ArrayList<String> listOfItems = new ArrayList<String>();

....
final ArrayAdapter<String> itemAdapter = new ArrayAdapter<String>(this, R.layout.list_item, listOfItems);

If I use a custom adapter that extends ArrayAdapter so that I can set the font of the TextView to a custom font, the font gets set correctly but the background highlighting no longer works. Any ideas?

public class ListItemAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final ArrayList<String> values;

    public ListItemAdapter(Context context, ArrayList<String> values) {
        super(context, R.layout.list_item, values);
        this.context = context;
        this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_item, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.text1);

        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/font-file.otf"); 
        textView.setTypeface(tf);
        textView.setText(values.get(position));
        return rowView;
    }
}
  • 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-09T06:13:39+00:00Added an answer on June 9, 2026 at 6:13 am

    Try this. It worked forme. it might help u too.

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_item, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.text1);
    
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/font-file.otf"); 
        textView.setTypeface(tf);
        textView.setText(values.get(position));
    
        rowView.setOnClickListener(new OnClickListener() {              
            @Override
            public void onClick(View arg0) {
                arg0.setBackgroundResource(R.drawable.<background>);                    
            }
        });
        return rowView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An OnItemClickListener for a ListView has the following method: @Override public void onItemClick(AdapterView<?> parent,
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View item, int position, long id)
I have listview control.There is an option to remove selected items.After the user removes
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have ListView in my project which has ListItems as in the form of
I have a listView with an OnItemClickListener. When I am clicking on an item,
i have some listview and SimpleAdapter List<HashMap<String, Object>> dataList = new ArrayList<HashMap<String, Object>>(); HashMap<String,
I have a ListView with an OnScrollListener and an OnItemClickListener . When I click
I have a ListView where each ListItem has 2 TextViews in it's layout. I'd
i have a listview and i would like to go to a new activity

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.