Back to project page ShareList-Android.
The source code is released under:
GNU General Public License
If you think the Android project ShareList-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.mybop.sharelist.app.view; //from w w w .j ava 2 s .com import android.content.Context; import android.database.Cursor; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.j256.ormlite.stmt.GenericRowMapper; import org.mybop.sharelist.app.R; import org.mybop.sharelist.app.database.entity.ListEntity; import org.mybop.sharelist.app.view.support.OrmLiteAdapter; import java.sql.SQLException; /** * Created by gautier on 16/03/2014. */ public class ListAdapter extends OrmLiteAdapter<ListEntity> { private static final String LOGGER_TAG = ListAdapter.class.getSimpleName(); public ListAdapter(Context context, Cursor cursor, GenericRowMapper<ListEntity> rowMapper) { super(context, cursor, rowMapper); } @Override protected void bindView(View view, Context context, ListEntity item) { Log.d("list adapter", "bind view: " + item.getId()); TextView label = (TextView) view.findViewById(R.id.label); TextView uncheckedCount = (TextView) view.findViewById(R.id.uncheckedCount); TextView count = (TextView) view.findViewById(R.id.count); label.setText(item.getName()); count.setText('(' + Integer.toString(item.getNumberOfElements()) + ')'); int unchecked = 0; try { unchecked = item.getNumberOfUncheckedElements(); } catch (SQLException e) { Log.e(LOGGER_TAG, "unable to found unchecked count", e); e.printStackTrace(); } if (unchecked > 0) { uncheckedCount.setText(Integer.toString(unchecked)); uncheckedCount.setBackgroundResource(R.drawable.shape_green_circle); } else { uncheckedCount.setText(""); uncheckedCount.setBackgroundResource(R.drawable.ic_action_checked_green); } DisplayMetrics metrics = context.getResources().getDisplayMetrics(); label.setMaxWidth(metrics.widthPixels - 2 * context.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_padding) - context.getResources().getDimensionPixelSize(R.dimen.touchable_element_size) - 4 * context.getResources().getDimensionPixelSize(R.dimen.space_between_elements) - 2 * context.getResources().getDimensionPixelSize(R.dimen.simple_icon_size)); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { return getLayoutInflater().inflate(R.layout.listitem_list, parent, false); } @Override protected void onContentChanged() { Log.d(LOGGER_TAG, "on content changed"); } }