Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FotoVerite/132957 to your computer and use it in GitHub Desktop.
Save FotoVerite/132957 to your computer and use it in GitHub Desktop.
package com.matthewbergman.exitstrategy.adapters;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.view.View;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
import com.matthewbergman.exitstrategy.R;
import com.matthewbergman.exitstrategy.database.DataBaseHelper;
public class SubwayLineAdapter extends ResourceCursorAdapter {
private Context context;
public SubwayLineAdapter(Context context, int layout, Cursor c){
super(context, layout, c);
this.context = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView lineControl = (TextView) view.findViewById(R.id.subwayline_block);
if (lineControl != null)
{
String line = cursor.getString(cursor.getColumnIndexOrThrow(DataBaseHelper.KEY_LINE));
lineControl.setText(line);
String colorName = cursor.getString(cursor.getColumnIndexOrThrow(DataBaseHelper.KEY_COLOR));
int colorResource = setColor(colorName);
lineControl.setBackgroundResource(colorResource);
}
}
public int setColor(String colorName) {
Resources resources = context.getResources();
int resId = resources.getIdentifier(colorName, "color", "com.matthewbergman.exitstrategy");
return resId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment