I have 4 TextViews, 2 ImageViews, 2 Buttons and 2 widgets that are part of a row definition in a ListView. The data comes from XML and a SimpleAdapter. To access these TextViews I implement the ViewBinder in a custom class and override the setViewValue. This works and the two TextViews I want to dynamically change are handled in the setViewValue. What is confusing to me is why my other two TextViews don't get passed through setViewValue. I say this based upon setting a breakpoint where the execution thread only enters twice. I was expecting to see it 4 or more times?
Here is the setViewValue where I have a breakpoint set.
@Override
public boolean setViewValue(View view, Object data, String text)
{
if(view.getId() == R.id.txtvw1)
{
//blah do some stuff
}
else if (view.getId() == R.id.txtvw2)
{
//Blah do some stuff
}
return true;
}
xml declaration of the TextViews(1 shows and 4 doesn't):
<TextView
android:id="@+id/txtvw1"
android:layout_centerHorizontal="true"
android:layout_width="185dp"
android:layout_height="25dp"
android:textSize="20sp"
android:layout_marginTop="60dp"
android:gravity="center"
android:inputType="none"
android:text="@string/str_StaticA"
android:textColor="#C0F700" />
<TextView
android:id="@+id/txtvw4"
android:layout_alignParentLeft="true"
android:layout_marginLeft="35dp"
android:layout_width="95dp"
android:layout_height="50dp"
android:textSize="18dp"
android:layout_marginTop="110dp"
android:gravity="center"
android:inputType="none"
android:text="IMHO:"
android:textColor="#FFBA19" />
So in summary why does the execution enter the override only twice AND it just so happens to be the exact two I want to update?
Well through additional reading and deductive reasoning a few more pieces of information have come to light. In my mind ever View in the ListView row XML would pass through the ViewBinder but that was WRONG! From what I can figure you attach the ViewBinder to the DataAdapter via setViewBinder. Well since the DataAdapter is told what View(s) to use to populate the data in it it makes sense that only the two were showing. I was only revealing two to it.
Here is a snippet where I specify the Views involved in the populating process and pass them on the constructor of the DataAdapter:
String[] from = new String[] {"txtvw_PrevLift", "txtvw_PrevReps", "ActuLiftPikr", "ActulRepsPikr" };
int[] to = {R.id.txtvw_PrevLift, R.id.txtvw_PrevReps, R.id.ActuLiftPikr, R.id.ActulRepsPikr };
LiftDataAdapter LiftDataAdapter = new LiftDataAdapter(this, LiftDataMaps, R.layout.liftdatalayout, from, to);
While this seems to make sense I don't know that my deductive reasoning is accurate. Will update as I find more information.
If you set a
ViewBinderonSimpleAdapterall theViewsyou declared(in thetoarray in your case) will be passed to theViewBinder'ssetViewValue()method no matter what. If thesetViewValuemethod doesn't returntruemeaning the data binding for thatViewhas failed(for whatever reason) then you get the default action(for aTextView), setting the text from the dataHashmap. Right now you declared thesetViewValueto do something for only twoTextViews(checking by their ids) and also to returntrueno matter what. When you'll enter thesetViewValuefor the otherViewsin your row layout you'll again enter thesetViewValue, don't match the ids(so no updates for thoseViews) and returntrue(which will tell the adapter that the binding was successful and thisViewdoesn't require any more work). A look at the source code for theSimpleAdapter.bindViewmethod will show you how theViewBinderis used.Also, I see that you use a custom adapter, are you sure you don't interfere with the normal
SimpleAdapterlogic?(also don't use the same name for the class and variable name)