我想做一件非常简单的事情。我的应用程序中有一个列表视图,我动态地向其中添加文本。但是,在某一点之后,我想更改列表视图中文本的颜色。因此,我创建了一个 XML 来定义我的自定义列表项,并将 ArrayAdapter 子类化。但是,每当我在自定义 ArrayAdapter 上调用 add() 方法时,都会将一个项目添加到列表视图中,但不会将文本放入其中。
这是我的 XML:`
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_content" android:textSize="8pt"
android:gravity="center" android:layout_margin="4dip"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#FF00FF00"/>
还有我的 ArrayAdapter 子类:
private class customAdapter extends ArrayAdapter<String> {
public View v;
public customAdapter(Context context){
super(context, R.layout.gamelistitem);
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
this.v = convertView;
if(v==null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.gamelistitem, null);
}
if(timeLeft!=0) {
TextView tv = (TextView)v.findViewById(R.id.list_content);
//tv.setText(str[pos]);
tv.setTextColor(Color.GREEN);
}
else {
TextView tv = (TextView)v.findViewById(R.id.list_content);
//tv.setText(str[pos]);
tv.setTextColor(Color.RED);
}
return v;
}
}
我确定我做错了什么,但我对 Android 还是有点陌生。
谢谢!`