Created
June 19, 2009 23:59
-
-
Save FotoVerite/132957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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