Looks like there are two possible ways to change something in the ListView rows:
-
using of
setViewBinder/setViewValue:myCursor.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); switch(viewId) { case R.id.icon: // change something related to the icon here -
using of
getView/LayoutInflater:public View getView(int position, View convertView, ViewGroup parent) {
View itemView = null; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); itemView = inflater.inflate(R.layout.list_row, null); } else { itemView = convertView; } ImageView imgViewChecked = (ImageView) itemView .findViewById(R.id.icon); // change something related to the icon here
What is the difference between these two approaches?
You can use both of them to accomplish the same task.
The ViewBinder system is added by SimpleCursorAdapter to make things easier for you, so you don’t have to write the entire getView code. In fact, SimpleCursorAdapter just implements getView by calling the setViewValue method (along with the standard boilerplate error checking and inflating)
I’ve attached the implementation that the Android source code uses for getView in SimpleCursorAdapter: