如何从ListView中没有的按钮更改列表视图中的文本颜色?我有一个按钮
tvbutton.setOnClickListener(new View.OnClickListener() {
ListView tv = (ListView)findViewById(R.id.tvlist);
TextView n = (TextView)[MY ISSUE IS RIGHT HERE, I NEED THE VIEW IN THE LISTVIEW AND I HAVE NO IDEA HOW TO GET IT].findViewById(R.id.x);
n.setTextColor(WHATEVERCOLOR);
}});
我在这里从sqlite中提取数据 SQLiteDatabase sqLiteDatabase = controller.getReadableDatabase();
String query = "SELECT DISTINCT * FROM blah";
final Cursor cursor = sqLiteDatabase.rawQuery(query, null);
tv.setAdapter(new TVAdapter(context, cursor, 0));
这是我的TVAdapter
private static final class TVAdapter extends CursorAdapter {
MyTVAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mInflater
.inflate(R.layout.tvview, parent, false);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView iv = (ImageView) view.findViewById(R.id.x1);
TextView n = (TextView) view.findViewById(R.id.x);
n.setText(cursor.getString(cursor.getColumnIndex("blahsds")));
loader.init(ImageLoaderConfiguration.createDefault(context));
loader.displayImage(cursor.getString(cursor.getColumnIndex("blahsblahs")),iv, op);
}
LayoutInflater mInflater;
}
答案 0 :(得分:0)
您应该调用适配器而不是listview
private static final class TVAdapter extends CursorAdapter {
private int color = 0xFF000000; // default
LayoutInflater mInflater;
MyTVAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mInflater
.inflate(R.layout.tvview, parent, false);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView iv = (ImageView) view.findViewById(R.id.x1);
TextView n = (TextView) view.findViewById(R.id.x);
n.setText(cursor.getString(cursor.getColumnIndex("blahsds")));
n.setTextColor(color);
loader.init(ImageLoaderConfiguration.createDefault(context));
loader.displayImage(cursor.getString(cursor.getColumnIndex("blahsblahs")),iv, op);
}
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
notifyDataSetChanged();
}
}
只需拨打adapter.setColor(0xFFFF0000);
,例如