我有一个动态编程的 textView 列表...
GridView layout = (GridView) context.findViewById(R.id.linearLayout1);
PrizeAdapter adapter = new PrizeAdapter(context, 0, 0, game.getPrizeList());
layout.setAdapter(adapter);
适配器类:
public class PrizeAdapter extends ArrayAdapter<String> {
private List<String> objects;
public PrizeAdapter(Context context, int resource, int textViewResourceId,
List<String> objects) {
super(context, resource, textViewResourceId, objects);
this.objects = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView text = new TextView(getContext());
text.setId(position);
text.setText(objects.get(position));
text.setTextSize(12);
text.setPadding(0, 5, 0, 5);
text.setTextColor(Color.WHITE);
text.setBackgroundColor(Color.GRAY);
text.setGravity(Gravity.CENTER | Gravity.BOTTOM);
return text;
}
}
据说,我创建了一个 10 TextView。我怎样才能获得特定的 textView 以便我可以用不同的颜色对其进行着色。
我试过这个
GridView layout = (GridView) context.findViewById(R.id.linearLayout1);
TextView view = (TextView) layout.findViewById(1);
view.setBackgroundColor(Color.YELLOW);
view.setTextColor(Color.RED);
但它不起作用,只是遇到了一个空指针异常。请帮忙。