Aha!
android.R.layout.simple_list_item_1 is defined in the platform, you can
find it under <your Android sdk
directory>/platforms/platform-<version>/data/res/layout (that data/res is
very useful to look up things):
The whole layout is a TextView, and its id is "@android:id/text1", which,
on the Java side of things, is android.R.id.text1.
So you'd do something like.
@Override
public View getView(int position, View convertView, ViewGroup
parent) {
View row = super.getView(position, convertView, parent);
* TextView text = (TextView) row.findViewById(android.R.id.text1);
* text.setTextColor(0x64788e);
return row;
}
Or just this, knowing that the layout is just one TextView:
*TextView text = (TextView) row;*
The direct typecast should work for the hello-listview sample, as that also
uses a row layout containing a single TextView with no children (and no id,
so findViewById won't work here).
-- Kostya
5 января 2012 г. 21:04 пользователь John Davis <[email protected]> написал:
> Hello
>
> On Thu, Jan 5, 2012 at 11:53 AM, Kostya Vasilyev <[email protected]>
> wrote:
> > Just to clarify 2:
> >
> > I meant calling super.getView from your adapter's getView, assuming it's
> a
> > subclass of ArrayAdapter.
> >
> > Do not call adapter.getView from outside the adapter's code, that's
> > meaningless.
>
> That makes sense. Thanks.
>
> >
> > Now the view ids.... What layout id do you use to initialize the adapter?
> > Perhaps android.R.layout.<something>?
>
> I did :
> MyAdapter<String> adapter = new
> MyAdapter<String>(this,android.R.layout.simple_list_item_1, values);
>
> >
> > A side note: my suggestions here are just to patch up things based on the
> > route you've already headed down (using ArrayAdapter).
>
>
> For what it is worth, I can do this:
> public View getView(int position, View convertView, ViewGroup
> parent) {
> TextView text = new TextView(getContext());
> text.setText("Hi, I am position " + position);
> text.setTextColor(Color.parseColor("#64788e"));
> return text;
> }
> That will set the text color to blue, but it will also change the text
> I put in the list.
>
> >
> > One day, as your knowledge grows, you'll want to throw away the
> > three-wheeled bicycle (ArrayAdapter) and create your own, perhaps by
> > extending BaseAdapter.
> >
>
>
> Is this example
> http://developer.android.com/resources/tutorials/views/hello-listview.html
> impossible to manipulate the color of individual list items? Or, is
> there a way to patch up this code to do what I want? It seems pretty
> trivial to do. I don't understand why the hooks do not exist for what
> i want to do.
> > -- Kostya
> >
> > 5 января 2012 г. 20:47 пользователь John Davis <[email protected]>
> написал:
> >
> >> Hello Kostya,
> >>
> >> Thanks for the reply.
> >>
> >> On Thu, Jan 5, 2012 at 11:39 AM, Kostya Vasilyev <[email protected]>
> >> wrote:
> >> >
> >> > 2:
> >> >
> >> > Yes, you're supposed to call the base class in your case, the
> >> > ArrayAdapter
> >> > will be doing most of the work for you, inflating new or reusing
> >> > existing
> >> > row layouts.
> >>
> >> Ok. I think I am doing what you say.
> >>
> >> >
> >> > 3:
> >> >
> >> > Use view ids that are relevant to (used inside) your actual row item
> >> > layout.
> >> >
> >> > I very much doubt that R.id.listView1 is it.
> >>
> >> The listview is created using that id. I did not create any resources
> >> for the individual items. I don't know how to do that. The example
> >> code I used simply created a listview in xml.
> >>
> >> >
> >> > 4:
> >> >
> >> > view.findViewById() is the getChild call you're looking for, using an
> id
> >> > to
> >> > locate the view. Use correct id value and it should work.
> >>
> >> Super. I am glad you confimed I need ot do that. However, as I said,
> >> I don't know what would be the id of the row items since they are not
> >> defined.
> >>
> >> >
> >> > -- Kostya
> >> >
> >> > 5 января 2012 г. 20:31 пользователь John Davis <[email protected]>
> >> > написал:
> >> >>
> >> >> Hello
> >> >>
> >> >> The getView() call for arrayadapter is blank. Is there a document
> >> >> which describes how it works?
> >> >>
> >> >> I have overridden it in order to change the text color of items in a
> >> >> list view. So far, I can't find any code which works.
> >> >>
> >> >> I've tried this:
> >> >>
> >> >> public class MyAdapter<T> extends ArrayAdapter<T> {
> >> >>
> >> >> public MyAdapter(Context context, int textViewResourceId, T[]
> >> >> objects) {
> >> >> super(context, textViewResourceId, objects);
> >> >> }
> >> >> // context, int, <T>[]
> >> >>
> >> >> @Override
> >> >> public View getView(int position, View convertView, ViewGroup
> >> >> parent) {
> >> >> // TODO Auto-generated method stub
> >> >> View row;
> >> >> row = super.getView(position, convertView, parent);
> >> >> TextView text;
> >> >> text = (TextView) row.findViewById(R.id.listView1);
> >> >> text.setTextColor(0x64788e);
> >> >> return row;
> >> >> }
> >> >> }
> >> >>
> >> >>
> >> >> I don't know if I am supposed to call getView in the main code or
> not,
> >> >> but this will most certain crash the app.
> >> >> The super.getView call seems to get a row in the list. It seems
> that
> >> >> you then need to get the view associated with that row. I have no
> >> >> idea how to do that. I don't have resource id's for the individual
> row
> >> >> items. Here, I tried to use the resource id of the list itself.
> >> >> There is not a View.getChild() like call.
> >> >> --
> >> >> John F. Davis
> >> >>
> >> >> 独树一帜
> >> >>
> >> >> --
> >> >> You received this message because you are subscribed to the Google
> >> >> Groups "Android Developers" group.
> >> >> To post to this group, send email to
> >> >> [email protected]
> >> >> To unsubscribe from this group, send email to
> >> >> [email protected]
> >> >> For more options, visit this group at
> >> >> http://groups.google.com/group/android-developers?hl=en
> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "Android Developers" group.
> >> > To post to this group, send email to
> [email protected]
> >> > To unsubscribe from this group, send email to
> >> > [email protected]
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/android-developers?hl=en
> >>
> >>
> >>
> >> --
> >> John F. Davis
> >>
> >> 独树一帜
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Android Developers" group.
> >> To post to this group, send email to
> [email protected]
> >> To unsubscribe from this group, send email to
> >> [email protected]
> >> For more options, visit this group at
> >> http://groups.google.com/group/android-developers?hl=en
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> > http://groups.google.com/group/android-developers?hl=en
>
>
>
> --
> John F. Davis
>
> 独树一帜
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en