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 12:03 PM
Thanks and ok.


Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: Scott Boren <[address removed]>
Sender: [address removed]
Date: Thu, 5 Jan[masked]:56:15 
To: <[address removed]>
Reply-To: [address removed]
Subject: RE: [tridroid] Hi, I am trying to set individual colors of text
 rows in a listView

Folks,

Might it be a good idea to reply only to each other rather than everyone getting all your emails on this specific problem?

Scott Boren
[masked] (direct)



The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it.

From: [address removed] [mailto:[address removed]] On Behalf Of John F. Davis
Sent: Thursday, January 05,[masked]:53 AM
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]






--
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 Scott Boren ([address removed]) from TriDroid - NC Triangle Android Meetup.
To learn more about Scott Boren, 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

  • Apex Systems

    Apex Systems is a technical staffing and recruitment solutions firm.

  • JetBrains

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

  • Xamarin

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

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