Java tutorial
/* * Copyright (C) 2012 Picon software * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package fr.eoidb.activity.util; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import fr.eoidb.R; import fr.eoidb.util.IconUtil; /** * @author picon.software */ public class ItemAttributeListViewBinder implements SimpleCursorAdapter.ViewBinder { private long id = 0; @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); switch (viewId) { case R.id.attribute_name: case R.id.attribute_unit: case R.id.attribute_value: String value = cursor.getString(columnIndex); initTextView(view, value); break; case R.id.attribute_icon: id = cursor.getLong(columnIndex); initIcon(view, id); break; default: throw new IllegalArgumentException("viewId : " + viewId); } return true; } private void initIcon(View view, long id) { ImageView imageView = (ImageView) view; IconUtil.initIcon(id, imageView); } private void initTextView(View view, String value) { TextView textView = (TextView) view; textView.setText(value); } }