addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [tridroid] Hi, I am trying to set individual colors of text rows in a listView

From: William D. L.
Sent on: Thursday, January 5, 2012 11:55 AM
Guys this is an awesome conversation.  I am able to follow a lot of what you are saying because I am taking a C++ class.  Thanks.


William D. Lee 
Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: "John F. Davis" <[address removed]>
Sender: [address removed]
Date: Thu, 5 Jan[masked]:53:06 
To: <[address removed]>
Reply-To: [address removed]
Subject: Re: [tridroid] Hi, I am trying to set individual colors of text
 rows in a listView

Hi Fred,

Maybe that is the problem, I am using an ArrayAdapter per this example:
http://developer....­


2012/1/5 Fred Medlin <[address removed]>:
> Try this:
>
>  public View getView(int position, View convertView, ViewGroup parent) {
>            TextView text = new TextView(getContext(­));
>            text.setText("Hi, I am position " + position);
>            text.setTextColor(Co­lor.parseColor("#647­88e"));
>            return text;
>  }
>
> Unless you have an Adapter super class that actually inflates a list item
> layout, your code sample just isn't going to work. If you're using
> BaseAdapter or ArrayAdapter, it won't happen. The row object is going to be
> null.
>
> Also suspect, the findViewById looks like it is searching for a listView
> rather than a textView.
>
> Come out to the next hack night and we can get you on the right path.
>
> 2012/1/5 John F. Davis <[address removed]>
>>
>> Hello Fred,
>>
>> I guess I should restate this simply.  I will be happy at this point
>> to programatically set the color of all items in a list view.
>>
>> I've tried this but it craps out.
>>
>>        public View getView(int position, View convertView, ViewGroup
>> parent) {
>>                // TODO Auto-generated method stub
>>                View row;
>>            row = super.getView(positi­on, convertView, parent);
>>            TextView text;
>>            text = (TextView) row.findViewById(R.i­d.listView1);
>> //          text.setTextColor(0x­64788e);
>>            text.setTextColor(Co­lor.parseColor("#647­88e"));
>>                return row;
>>        }
>>
>>
>> I got that approach from this sample code:
>> public View getView(int position, View convertView,
>> ViewGroup parent) {
>> View row=super.getView(po­sition, convertView, parent);
>> ImageView icon=(ImageView)row.­findViewById(R.id.ic­on);
>> if (items[position].len­gth()>4) {
>> icon.setImageResourc­e(R.drawable.delete);­
>> }
>> else {
>> icon.setImageResourc­e(R.drawable.ok);
>> }
>> return(row);
>> }
>>
>>
>>
>> 2012/1/5 Fred Medlin <[address removed]>:
>> > I can't tell if that is just a throw away code sample or not, but you
>> > probably shouldn't be getting your rowView from super().
>> >
>> > Generally in the getView() call you should be creating/inflating a new
>> > view
>> > each time. If convertView is not null, you can reuse/recycle it., but
>> > for
>> > debug try creating a new TextView each time getView is called.
>> >
>> > Also, setTextColor() takes an int, but I've never seen it expressed as a
>> > binary like that. I'm not sure you can directly use those values. You
>> > can
>> > try:
>> >
>> > setTextColor(Color.r­gb(100,120,142)           - or -
>> > setTextColor(Color.p­arseColor("#64788e")­
>> >
>> > 2012/1/5 John F. Davis <[address removed]>
>> >>
>> >> Hello Fred,
>> >>
>> >> I tried that:
>> >>
>> >>        public View getView(int position, View convertView, ViewGroup
>> >> parent) {
>> >>                // TODO Auto-generated method stub
>> >>                View rowView;
>> >>            rowView = (TextView) super.getView(positi­on, convertView,
>> >> parent);
>> >> //          ((TextView)rowView).­setTextColor(0x64788­e);
>> >>            rowView.setBackgroun­dColor(0x64788e);
>> >>                return rowView;
>> >>        }
>> >>
>> >> It does nothing.  The text is still white/gray.
>> >>
>> >> 2012/1/5 Fred Medlin <[address removed]>:
>> >> > Color based on which row the text is in?
>> >> >
>> >> > Do it in the adapter for the list view.
>> >> >
>> >> > public View getView (int position, View convertView, ViewGroup
>> >> > parent) {
>> >> >
>> >> >     // use the position as the hint
>> >> >     // for example to stripe the background:
>> >> >     // setBackground(positi­on % 2 == 0 ? R.color.even_stripe :
>> >> > R.color.odd_stripe);­
>> >> >
>> >> >     // or get the data to decide what color
>> >> >     // Object thing = getItem(position);
>> >> >     // set color based on object thingy
>> >> > }
>> >> >
>> >> >
>> >> > HTH,
>> >> >
>> >> > Fred
>> >> >
>> >> > 2012/1/5 John F. Davis <[address removed]>
>> >> >>
>> >> >> Anyone know how to do this?
>> >> >>
>> >> >> --
>> >> >> John F. Davis
>> >> >>
>> >> >> 独树一帜
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Please Note: If you hit "REPLY", your message will be sent to
>> >> >> everyone
>> >> >> on
>> >> >> this mailing list ([address removed])
>> >> >> http://www.meetup...­
>> >> >> This message was sent by John F. Davis ([address removed]) from
>> >> >> TriDroid -
>> >> >> NC Triangle Android Meetup.
>> >> >> To learn more about John F. Davis, visit his/her member profile:
>> >> >> http://www.meetup...­
>> >> >> To unsubscribe or to update your mailing list settings, click here:
>> >> >> http://www.meetup...­
>> >> >> Meetup, PO Box 4668 #37895 New York, New York[masked] |
>> >> >> [address removed]
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Please Note: If you hit "REPLY", your message will be sent to
>> >> > everyone
>> >> > on
>> >> > this mailing list ([address removed])
>> >> > This message was sent by Fred Medlin ([address removed]) from
>> >> > TriDroid -
>> >> > NC
>> >> > Triangle Android Meetup.
>> >> > To learn more about Fred Medlin, visit his/her member profile
>> >> > To unsubscribe or to update your mailing list settings, click here
>> >> >
>> >> > Meetup, PO Box 4668 #37895 New York, New York[masked] |
>> >> > [address removed]
>> >>
>> >>
>> >>
>> >> --
>> >> John F. Davis
>> >>
>> >> 独树一帜
>> >>
>> >>
>> >>
>> >> --
>> >> Please Note: If you hit "REPLY", your message will be sent to everyone
>> >> on
>> >> this mailing list ([address removed])
>> >> http://www.meetup...­
>> >> This message was sent by John F. Davis ([address removed]) from
>> >> TriDroid -
>> >> NC Triangle Android Meetup.
>> >> To learn more about John F. Davis, visit his/her member profile:
>> >> http://www.meetup...­
>> >> To unsubscribe or to update your mailing list settings, click here:
>> >> http://www.meetup...­
>> >> Meetup, PO Box 4668 #37895 New York, New York[masked] |
>> >> [address removed]
>> >>
>> >
>> >
>> >
>> >
>> >
>> > --
>> > Please Note: If you hit "REPLY", your message will be sent to everyone
>> > on
>> > this mailing list ([address removed])
>> > This message was sent by Fred Medlin ([address removed]) from TriDroid -
>> > NC
>> > Triangle Android Meetup.
>> > To learn more about Fred Medlin, visit his/her member profile
>> > To unsubscribe or to update your mailing list settings, click here
>> >
>> > Meetup, PO Box 4668 #37895 New York, New York[masked] |
>> > [address removed]
>>
>>
>>
>> --
>> John F. Davis
>>
>> 独树一帜
>>
>>
>>
>> --
>> Please Note: If you hit "REPLY", your message will be sent to everyone on
>> this mailing list ([address removed])
>> http://www.meetup...­
>> This message was sent by John F. Davis ([address removed]) from TriDroid -
>> NC Triangle Android Meetup.
>> To learn more about John F. Davis, visit his/her member profile:
>> http://www.meetup...­
>> To unsubscribe or to update your mailing list settings, click here:
>> http://www.meetup...­
>> Meetup, PO Box 4668 #37895 New York, New York[masked] |
>> [address removed]
>>
>
>
>
>
>
> --
> Please Note: If you hit "REPLY", your message will be sent to everyone on
> this mailing list ([address removed])
> This message was sent by Fred Medlin ([address removed]) from TriDroid - NC
> Triangle Android Meetup.
> To learn more about Fred Medlin, visit his/her member profile
> To unsubscribe or to update your mailing list settings, click here
>
> Meetup, PO Box 4668 #37895 New York, New York[masked] |
> [address removed]



-- 
John F. Davis

独树一帜



--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
http://www.meetup...­
This message was sent by John F. Davis ([address removed]) from TriDroid - NC Triangle Android Meetup.
To learn more about John F. Davis, visit his/her member profile: http://www.meetup...­
To unsubscribe or to update your mailing list settings, click here: http://www.meetup...­
Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

  • JetBrains

    Makers of Android Studio (IntelliJ IDEA for Android java development)

  • Ticketmaster Mobile Studio

    Hosting meetups at American Tobacco campus - Durham, NC

  • TransLoc

    Better public transportation for everyone

  • Smashing Boxes

    Hosting meetups at American Tobacco campus - Durham, NC

  • Xamarin

    Write apps entirely in C#, share code on iOS, Android, Windows and Mac.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy