views:

58

answers:

2

I want to be able to access my ArrayAdapter's view:

public View getView(int position, View convertView, ViewGroup parent)

I'm not sure how I can access this:

View myView = myArrayAdapter.getView(myPosition, myView, ?);

I am not sure how I can get a ViewGroup parent?

A: 

Update:

Try adding a field to the data in the data set that holds the background resource/color to be used when returning the view, and in the getView do

holder.background = dataSet.get(position).getBackground()

If you don't know what I'm talking about with this holder thing, check http://stackoverflow.com/questions/1320478/how-to-load-the-listview-smoothly-in-android

Old:

I'd say the ListView containing the adapter is the parent ViewGroup.

Anyway, why don't you use the ListView containing the ArrayAdapter? The ListView is the container of the Views, rather than the adapter, that only holds the data collection and creates and returns Views on demand when the ListView asks for them (f.e, when scrolling). Even if you were able to fetch a view for the position X, I'd say that won't work, as the convertView you pass as a parameter is not the one the ListView is holding and showing.

Take into account that in a ListView there are at most 7-8 Views inflated at any given moment (I don't know the exact number), and what the ListView does is fill them in by calling the adapter's getview.

This said, to update a single row (a single view) you'll need to update the adapter's data collection. Then, speculating, try to get that View from the ListView and invalidate it, but I doubt this'll work.

I think these concepts are right, if they are wrong I'd be grateful if anyone corrects me.

Why do you want to update only one view at a time?

Maragues
i want to make row selection seem sticky, so I want to change the background of the selected view.
Sheehan Alam
I've updated the answer. Also, the rule to follow in your scenario is to update the whole ListView, not a single row.
Maragues
A: 

Well as far as I understand you don't suppose to Adapter in general serves as a source to instance of AdapterView so getView contract is follows :
in params : inPosition,convertView,viewParent
result : View witch will be shown at position inPosition , you can use convertView to bind data to if it's not null, returned view will be attached to viewParent.

So if you want to acquire view that will be shown by adapter view at specific position, why don't just call

AdapterView<?> adapterView = getAdapterView();
View myView = adapterView.getChildAt(position);

If you want to change way of showing view at specific position you should use

Adapter myAdapter = getAdapter();
//change data inside adapter
myAdapter.notifyDataSetChanged();
Nikolay Ivanov