Android:更改listview行布局中的textview设置(setTextColor)

Android:更改listview行布局中的textview设置(setTextColor),android,Android,有点复杂的标题,但我不知道如何用不同的方式来表达 我有1个活动和2个布局xml文件。 在1st.xml中有listview,在2nd.xml中有表示listview中的行的项。在本教程中,它看起来像: 我的问题是:如何以编程方式更改2nd.xml(在tutorial grid_item.xml中)中的TextView设置 如果我调用text1.setTextColor(Color.RED),它向我抛出异常java.lang.NullPointerException问题已解决。 我制作了自己的适配

有点复杂的标题,但我不知道如何用不同的方式来表达

我有1个活动和2个布局xml文件。
在1st.xml中有listview,在2nd.xml中有表示listview中的行的项。在本教程中,它看起来像:

我的问题是:如何以编程方式更改2nd.xml(在tutorial grid_item.xml中)中的TextView设置
如果我调用
text1.setTextColor(Color.RED),它向我抛出异常java.lang.NullPointerException

问题已解决。
我制作了自己的适配器:

public class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[] { 0x30FF0000, 0x300000FF };
public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
    super(context, items, resource, from, to);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  View view = super.getView(position, convertView, parent);
  int colorPos = position % colors.length;
  view.setBackgroundColor(colors[colorPos]);
  return view;
}
公共类SpecialAdapter扩展了SimpleAdapter{
私有int[]颜色=新int[]{0x30FF0000,0x300000FF};
公共SpecialAdapter(上下文上下文、列表项、int资源、字符串[]从、int[]到){
超级(上下文、项目、资源、发件人、收件人);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图=super.getView(位置、转换视图、父级);
int colorPos=位置%colors.length;
视图.setBackgroundColor(颜色[colorPos]);
返回视图;
}
}


这是从同一个网站,我张贴它。我想要更好的解决方案,但它能解决问题。

发布代码。如果该行抛出一个NPE,那么text1必须为null。请检查发布的链接…我的代码以与代码
text1.setTextColor(Color.RED)相同的方式编写在发布的链接中不存在。您需要向我们展示您的代码,否则我们只是猜测。