Question

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?

Was it helpful?

Solution

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 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?

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top