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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:48:35+00:00 2026-05-28T14:48:35+00:00

In my ArrayAdapter class I capture the context passed in. Then int the getView

  • 0

In my ArrayAdapter class I capture the context passed in. Then int the getView method, I have this if statement:

if(m.getSide() == RED) {
    v.setBackgroundColor(lc.getResources().getColor(R.color.red_bouy));
    Log.d("MA", "HERE");
} else if(m.getSide() == BLACK) {
    v.setBackgroundColor(lc.getResources().getColor(R.color.black_bouy));
}

(lc is the Context I grab from the Constructor)

If I just use Color.red, it works find. All examples I’ve seen use ghet getResources…, but from within an activity.
Any suggestions?

  • 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-28T14:48:37+00:00Added an answer on May 28, 2026 at 2:48 pm

    When you create adapter, you pass a Context to constructor. In getView() you can call getContext().getResources().get… Is this what you were looking for?

    Also, @MahdeTo is right: you seem to keep a live reference to context – don’t! You’ll leak your context. If you absolutely must, use WeakReference<Context> and check for null, but I don’t see why you would have to.

    UPD: Not really a problem with Adapters (tnx to @Arhimed and @Rperryng for pointing this out) since their proper usage ensures their lifecycle doesn’t exceed that of their Context, so it’s ok to store a live link to a Context [even if the adapter itself has a live ref in the Context — GC is pretty smart, isn’t fooled by circular refs]. Nevertheless, there’s no need to do that in this case: ArrayAdapter.getContext() is there for this exact purpose – so you can access resources and get an Inflater when you need one to build views in getView()

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

Sidebar

Related Questions

I have a subclass of an ArrayAdapter declared like this public class ShoppingCartAdapter extends
I have overrode the getView() method in ArrayAdapter . I was wondering if there
I have this Code to Capture a image and Display it back in ListView
I have been implementing a class which class extends ArrayAdapter and implements Filterable. The
I have a custom list adapter: class ResultsListAdapter extends ArrayAdapter<RecordItem> { in the overridden
I created an adapter public class MyArrayAdapter extends ArrayAdapter<Watch> overriding public MyArrayAdapter(Context context, List<Watch>
I have a listview with a custom array adapter: public class SmsMessageAdapter extends ArrayAdapter<ContactMessage>
I have written a ListActivity class that uses a custom ArrayAdapter and Holders. I
This is my code: public class demoProject1 extends Activity { int i; /** Called
class IconicAdapter extends ArrayAdapter<String> { Activity context=new Activity(); IconicAdapter(Activity context) { super(context, R.layout.topic_list_row, itemList);

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.